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 resp. 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 (only
LC ) 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.
- A while loop is often
used to modify a value slowly during a number of frames, e.g. to
open a door or to move an elevator. For this a wait instruction
is normally used at the end of the instruction set between
the winged brackets, to indicate that a frame time must pass for
each repetition.
- Loops can be prematurely terminated by break, and prematurely repeated
by continue.
- LC In lite-C, C, or C++,
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, goto, break, continue, comparisons
► latest
version online