The WHILE 7 REPEAT 7 END Structure
The syntax for this structure is
«… WHILE
WHILE … REPEAT … END repeatedly evaluates
Syntax | Flowchart |
WHILE
TEST
1: test result
REPEA T
Is test
result
no
yes
Body of loop |
| |||
|
|
|
|
|
END
WHILE 7 REPEAT 7 END Structure
WHILE starts execution of the
To enter WHILE 7 REPEAT 7 END in a program:
Press !°%BRCH% !%WHILE%.
Example: The following program starts with a number on the stack, and repeatedly performs a division by 2 as long as the result is evenly divisible. For example, starting with the number 24, the program computes 12, then 6, then 3.
«WHILE DUP 2 MOD 0 == REPEAT 2 / DUP END DROP »
Example: The following program takes any number of vectors or arrays from the stack and adds them to the statistics matrix. (The vectors and arrays must have the same number of columns.)
WHILE … REPEAT … END is used instead of DO … UNTIL … END because the test must be done before the addition. (If only vectors or arrays with the same number of columns are on the stack, the program errors after the last vector or array is added to the statistics matrix.)
«WHILE DUP TYPE 3 == REPEAT Σ+ END »