TAL Programmer's Guide
FOR Statement
Controlling Program Flow
12–12 096254 Tandem Computers Incorporated
FOR Statement The FOR statement is a repeating loop that executes a statement while incrementing or
decrementing an index automatically. The loop terminates when the index reaches a
limit value. If the index is greater than the limit on the first test, the loop never
executes.
To specify a FOR statement, include:
FOR index :=
Specifies a value that increments or decrements automatically until it reaches a
specified value and terminates the loop.
In a standard FOR loop, index is the identifier of an INT simple variable, array
element, simple pointer, or structure data item.
In an optimized FOR loop, index is the identifier of an index register you have
reserved by using the USE statement.
initial-value
An INT arithmetic expression (such as 0) that initializes index.
limit
An INT arithmetic expression specified as either:
TO limit—Increments index each time the loop executes until index exceeds
limit
DOWNTO limit—Decrements index each time the loop executes until index is
less than limit
BY step
An optional clause for specifying an INT arithmetic expression by which to
increment or decrement index. The default value is 1.
DO statement
Specifies the statement to execute each time through the loop. The statement can be
any TAL statement.
For example, this standard FOR loop clears an array by assigning a space to each
element in the array:
LITERAL len = 100;
LITERAL limit = len - 1;
STRING .array[0:limit];
INT index;
FOR index := 0 TO limit DO !Use default step of 1;
array[index] := " "; ! fill elements with spaces
FOR index := 4 TO limit BY 5 DO
array[index] := "!"; !Replace every fifth space
! with exclamation point