The do Statement

The do statement repeats a statement until a specified expression becomes false. The test expression in the loop is evaluated after the body of the loop executes. Thus, the body of a do loop always executes at least once.

Use a break, goto, or return statement when you need to exit a do loop early. Use the continue statement to terminate an iteration without exiting the loop. The continue statement passes control to the next iteration of the loop.

The following example illustrates do:

sample = 1;

do

printf( “%d\t%d\n”, sample, sample * sample );

while( ++x <= 7 );

The printf statement in the example always executes at least once, no matter what value x has when the loop begins.