while( condition ) statement
x = 5; while(x > 0) x--;
x = 0;
and the program would function
the same way.)
The loop:
a = 1; while(a < b) a *= 2;
b
.
Just as for the
if
statement, the body of the
while
may be a compound statement instead of just a single statement.
For example, one approach to a counted loop would look like:
i = 0;
while(i < 10) {
printf("%d\n", i);
i++;
}