The do while loop

The “do while loop” is almost the same as the while loop.

The “do while loop” has the following form:

do

{ do something;} while (expression) ;

Do something first and then test if we have to continue.

The result is that the loop always runs once. (Because the expression test comes afterward).

example:

        int main()
        {
               int counter, howmuch;
               scanf("%d", &howmuch);
               counter = 0;
               do
               {
                       counter++;
                       printf("%d\n", counter);
               }
               while ( counter < howmuch);
               return 0;
        }

Note: There is a semi-colon behind the while line.

The reference site for this content is 
http://www.nextdawn.nl/c-tutorial-for-loop-while-loop-break-and-
Back