TAL Programmer's Guide
DO Statement
Controlling Program Flow
12–10 096254 Tandem Computers Incorporated
DO Statement The DO statement is a repeating loop that executes a statement until a specified
condition becomes true. If the condition is always false, the loop repeats until a
statement in the DO loop causes an exit.
To specify a DO statement, include:
DO statement
Specifies a statement to execute until the condition becomes true. The statement can
be any TAL statement.
UNTIL condition
Specifies a condition that, if false, causes the DO loop to continue. If the condition
is true, the statement following this DO statement executes. The condition can be
either:
A conditional expression
An INT arithmetic expression. If the result of the arithmetic expression is not
0, the condition is true. If the result is 0, the condition is false.
A DO statement always executes at least once because the compiler tests the condition
at the end of the loop. Unless you have a special reason to use the DO statement, it is
safer to use the WHILE statement.
The following DO loop cycles through an array until each element is assigned a 0:
LITERAL len = 50;
LITERAL limit = len - 1;
INT i := 0;
STRING .array_a[0:limit]; !Declare array
DO !DO statement
BEGIN
array_a[i] := 0; !Compound statement to
i := i+1; ! execute in DO loop
END
UNTIL i > limit; !Condition for ending loop
!Rather than I = LEN
Figure 12-5 shows the action of the DO statement.