Monday, August 23, 2010

C do while loop

The do while statement creates a loop that repeats until the test expression becomes  false or zero.  The do while statement is an exit condition loop, which means that the decision to go through  one more pass of the loop is made after the loop is traversed.  Thus, the loop must be executed at least once.  The statement part of the form can be simple statement or a compound statement.


Form


do
     statement
         while(expression);


The statement portion is repeated until the expression becomes false or zero.

Example

1. do
     scanf("%d", &number);
          while(number != 20);



2.  /* do while .c */
     #include < stdio.h >
     main()
    {
           int j = 5;
           printf("start\n");
           do {
            printf( "j = %i\n", j--);
           } while(j >0);
           printf("stop\n");
          getch();
          return 0;
     }

0 comments: