Example: The following program takes n from the stack, and returns the series of numbers 1, 2, 4, 8, 16, …, n. If n isn’t in the series, the program stops at the last value less than n.
«1 SWAP FOR n n n STEP »
The first n is the local variable declaration for the FOR loop. The second n is put on the stack each iteration of the loop. The third n is used by STEP as the step increment.
Using Indefinite Loop Structures
The DO 7 UNTIL 7 END Structure
The syntax for this structure is
«… DO
DO… UNTIL… END executes the
Syntax | Flowchart |
| |
DO |
|
| |
Body of loop |
| ||
UNTIL | TEST |
| |
1: test result |
| ||
| Is test | no | |
END | result | ||
|
yes
DO 7 UNTIL 7 END Structure
DO starts execution of the
—otherwise, execution resumes following END. If the argument of END is an algebraic or a name, it’s automatically evaluated to a number.
To enter DO 7 UNTIL 7 END in a program:
Press !°%BRCH% !%DO%.