Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

Example of DO with WHILE, UNTIL

The WHILE and UNTIL options make successive executions of the do-group dependent upon a specified condition, for example:

  do while (A=B);

·
·
·
end;

is equivalent to the following:

  S:  if A=B then;
else goto R;

·
·
·
goto S; R: next statement

The example:

  do until (A=B);

·
·
·
end;

is equivalent to the following:

  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.

In the following example, if 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.

In the following example, the do-group is executed at least once, with 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.

The following statement specifies that the do-group executes ten times while 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);

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)