C Programming Language

do-while loop

              This construct is also used for looping. In this case the loop condition is tested at the end of the body of the loop. Hence the loop is executed at least one. The do-while is an unpopular area of the language, most programmers’ tries to use the straight while if it is possible.

Syntax of do while loop is
     Statement 1;
     Statement 2;
     Statement n;

                 Here the block of statement following the do is executed without any condition check. After this expression is evaluated and if it is true the block of statement in the body of the loop is executed again. Thus the block of statement is repeatedly executed till the expression is evaluated to false.

                  do-while construct is not used as often as the while loops or for loops in normal case of iteration but there are situation where a loop is to be executed at least one, in such cases this construction is very useful.

The following example illustrates the use of do-while loop.

do-while loop
while loop Home break statement
c program stats