next up previous contents
Next: 6.4 For Up: 6 Control Flow Previous: 6.2 If-Else

6.3 While

The syntax of a while loop is the following:

while ( expression )
statement

while begins by evaluating expression. If it is false, then statement is skipped. If it is true, then statement is evaluated. Then the expression is evaluated again, and the same check is performed. The loop exits when expression becomes zero.

One can easily create an infinite loop in C using the while statement:

while (1)
statement



Fred G. Martin
Fri Mar 29 17:44:15 EST 1996