Specifications
Commands - 35
DO/UNTIL
Statements
SYNTAX: DO
.
.
.
UNTIL expression is true
PURPOSE: To execute a conditional loop structure.
REMARKS: The DO/UNTIL statements cause a list of statements to be executed until a condition is met. You
may exit a DO/UNTIL with the EXIT statement
EXAMPLE: 10 A= - 45
20 DO
30 INC A:PRINT A
50 UNTIL A=0
Nesting DO/UNTIL loops is permitted. Care must be taken in the construct. The following example
illustrates one of the possible pitfalls:
10 DO
20 DO
30 INC X
40 UNTIL X=5
50 INC Y
60 UNTIL Y=5
In the “inside” loop beginning at line 20, variable X is incremented until X = 5. Line 50 is then
executed. Since Y is now 1, execution branches to line 20. The previous value of X was 5, and it is
now incremented to 6. Since this is greater than 5, the inside loop continues until X overflows (a
very long time).
One solution is to add line 45 to reset X each time so the program will run properly:
45 X=0
ERROR: <UNTIL> – if UNTIL encountered without corresponding DO.