Iterative DO Loop
A DO group may be repeated a certain number of times by specifying an index variable and a series of values for it to sequence. The DO group executes for each values of the index variable. The index variable may be used - and often is - in the execution of the DO group.
· These iterative DO statements use a list of items for the value of start:
o do month='JAN','FEB','MAR';
o do count=2,3,5,7,11,13,17;
o do i=5;
o do i=var1-var5;
o do i=var1, var2, var3;
o do i='01JAN2001'd,'25FEB2001'd,'18APR2001'd;
· These iterative DO statements use the start TO stop syntax:
o do i=1 to 10;
o do i=1 to exit;
o do i=1 to x-5;
o do i=1 to k-1, k+1 to n;
o do i=k+1 to n-1;
· These iterative DO statements use the BY increment syntax:
o do i=n to 1 by -1;
o do i=.1 to .9 by .1, 1 to 10 by 1,
o 20 to 100 by 10;
o do count=2 to 8 by 2;
· These iterative DO statements use WHILE and UNTIL clauses:
o do i=1 to 10 while(x<y);
o do i=2 to 20 by 2 until((x/3)>y);
o do i=10 to 0 by -1 while(month='JAN');
· In this example, the DO loop is executed when I=1 and I=2; the WHILE condition is evaluated when I=3, and the DO loop is executed if the WHILE condition is true.
DO I=1,2,3 WHILE (condition);