Example of DO with WHILE, UNTIL
The WHILE and UNTIL options make successive executions of the do-group dependent upon a specified condition.
Consider the following example:
do while (A=B);
.
.
.
end;
This example is equivalent to the following statement:
S: if A=B then;
else goto R;
.
.
.
goto S;
R: next statement
Consider the following example:
do until (A=B);
.
.
.
end;
This example is equivalent to the following statement:
S:
.
.
.
if (A=B) then goto R;
goto S;
R: next statement
In the absence of other options, a do-group headed by a DO UNTIL
statement is executed at least once, but a do-group headed by a DO
WHILE statement might not be executed at all. That is, the statements DO
WHILE (A=B) and DO UNTIL (A¬=B) are not
equivalent.
A¬=B, when the DO
statement is first encountered, the do-group is not executed at all.
do while(A=B) until(X=10);However, if A=B, the do-group is executed. If X=10 after
an execution of the do-group, no further executions are performed.
Otherwise, a further execution is performed provided that A is
still equal to B.
I equal to 1: do I=1 to 10 until(Y=1);If Y=1 after an execution of the do-group, no
further executions are performed. Otherwise, the default increment
(BY 1) is added to I, and the new value of I is
compared with 10. If I is greater than 10, no further
executions are performed. Otherwise, a new execution commences.
C(I) is less than zero, and then (provided
that A is equal to B) once more: do I = 1 to 10 while (C(I)<0),
11 while (A = B);