The FOR 7 NEXT Structure
The syntax for this structure is
«… start finish FOR counter
FOR … NEXT executes the
Syntax | Flowchart |
|
Start | 1:Start |
|
finish | 2:finish |
|
FOR | counter=start |
|
| Store finish |
|
Body of loop |
| |
| counter = counter + 1 |
|
NEXT |
|
|
| Is | yes |
| counter ≤ finish? | |
|
| |
| no |
|
FOR 7 NEXT Structure
FOR takes start and finish from the stack as the beginning and ending values for the loop counter, then creates the local variable counter as a loop counter. Then the
To enter FOR 7 NEXT in a program:
Press !°%BRCH% !%FOR%.
Example: The following program places the squares of the integers 1 through 5 on the stack:
«1 5 FOR j j SQ NEXT »
Example: The following program takes the value x from the stack and computes the integer powers i of x. For example, when x =12 and start and finish are 3 and 5 respectively, the program returns 123, 124 and 125. It requires as inputs start and finish in level 3 and 2, and x in level 1. (→ x removes x from the stack, leaving start and finish there as arguments for FOR.)
«→ x « FOR n 'x^n' EVAL NEXT » »