condition
While
is executed, the condition is evaluated. If condition is true, the
When
While
loop is executed; otherwise, control jumps to the command following
.
EndWhile
|
x
5
Note: The
While
You must include commands that allow the function or program to exit
the loop.
At the end of the loop (
command, where condition is re-evaluated.
To execute the loop the first time, the condition must initially be true.
•
Any variables referenced in the condition must be set before the
command. (You can build the values into the function or
While
program, or you can prompt the user to enter the values.)
•
The loop must contain commands that change the values in the
condition, eventually causing it to be false. Otherwise, the condition
is always true and the function or program cannot exit the loop
(called an infinite loop).
For example:
À
0
x
&
While x<5
Á
Disp x
Â
x+1
x
&
EndWhile
Ã
Disp x
À
Initially sets x.
Á
Displays 0, 1, 2, 3, and 4.
Â
Increments x.
Ã
Displays 5. When x increments to 5, the loop is not executed.
Programming
While x<5
x < 5
--------
--------
EndWhile
--------
command does not automatically change the condition.
EndWhile
), control jumps back to the
While
339