TAL Reference Manual

Statements
TAL Reference Manual526371-001
12-23
Usage Considerations
Usage Considerations
The FOR statement tests index at the beginning of each iteration of the loop. If index
passes limit on the first test, the loop never executes.
You can nest FOR loops to any level.
FOR statement execution is shown in the
TAL Programmer’s Guide.
Standard FOR Loops
For index, standard FOR loops specify an INT variable. Standard FOR loops execute
as follows:
When the looping terminates, index is greater than limit if:
°
The step value is 1.
°
You use the TO keyword (not DOWNTO).
°
The limit value (not a GOTO statement) terminates the looping.
limit and step are recomputed at the start of each iteration of the loop.
Optimized FOR Loops
For index, optimized FOR loops specify a register reserved by a USE statement.
Optimized FOR loops execute faster than standard FOR loops; they execute as
follows:
When the looping terminates, index is equal to limit.
limit is calculated only once, at the start of the first iteration of the loop.
You optimize a FOR loop as follows:
1. Before the FOR statement, specify a USE statement to reserve an index register.
2. In the FOR statement:
For index, use the identifier of the index register.
Omit the step value (thereby using the default value of 1).
For limit, use the TO keyword.
3. If you modify the register stack, save and restore it before the end of the loop.
(Modifying the register stack, however, is not an operation portable to future
software platforms.)
4. After the FOR statement, specify a DROP statement to release the index register.
Do not drop the index register during the looping.