while (comparison) { instructions... }
do { instructions... } while (comparison)
;
Repeats
all instructions between the winged brackets as long as the comparison between
the round brackets is true or evaluates to non-zero. This repetition
of instructions is called a loop. The while statement
evaluates the comparison at the begin, the do..while statement at the end of each repetition.
Remarks:
- If you
want the loop to run forever, simply use the
value 1 for
the comparison - 1 is always true.
- Loops can be prematurely terminated by break, and prematurely repeated
by continue.
- The winged brackets can be omitted when the loop contains only one
instruction.
Example:
x = 0;
while(x < 100) // repeat while x is lower than 100
x += 1;
See also:
if, for, break, continue, comparisons, loop
► latest
version online