In the following example, the do-group is executed with I equal to 1, 2, 4, 8, 16, and so on:
do I = 1 repeat 2*I;
·
·
·
end;
The preceding example is equivalent to:
I=1; A:
·
·
·
I=2*I; goto A;
In the following example, the first execution of the do-group is performed with I=1.
do I=1 repeat 2*I until(I=256);
After this and each subsequent execution of the do-group, the UNTIL expression is tested. If I=256, no further executions are performed. Otherwise, the REPEAT expression is evaluated and assigned to I, and a new execution commences.
The following example shows a DO statement used to locate a specific item in a chained list:
do P=Phead repeat P -> Fwd
while(P¬=null())
until(P->Id=Id_to_be_found);
end;The value Phead is assigned to P for the first execution of the do-group. Before each subsequent execution, the value P -> Fwd is assigned to P. The value of P is tested before the first and each subsequent execution of the do-group. If it is null, no further executions are performed.
The following statement specifies that the do-group is to be executed nine times, with the value of I equal to 1 through 9; then successively with the value of I equal to 10, 20, 40, and so on. Execution ceases when the do-group has been executed with a value of I greater than 10000.
do I = 1 to 9, 10 repeat 2*I
until (I>10000);
·
·
·
end;