The while Statement

The while statement repeats a statement until its test expression becomes false. A while loop evaluates its test expression before executing its loop body. If the test expression is false when the loop begins, the loop body never executes. (Contrast this behavior with the do loop, which always executes its loop body at least once.)

For example:

while( !sample ) /* Repeat until sample equals 1 */

{

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

x += 6;

if( x > 20 )

sample = 1;

}

You can exit a while loop early with a break or goto statement. The continue statement skips to the next iteration of the loop.