The DO statement controls a block of statements which are executed repeatedly, once for each value of a variable called the loop-control variable. The number of iterations depends on the parameters of the DO statement at the heads of the loop. The first item after the keyword ``DO" is the label which is attached to the last statement of the loop. For example:
*Sum the squares of the first N elements of the array X
SUM = 0.0
DO 15, I = 1,N
SUM = SUM + X(I)**2
15 CONTINUE
If we had wanted only to sum alternate elements of the array we
could have used a statement like: DO 15,I = 1,N,2
DO 100,I = 5,1,-1
WRITE(UNIT=*,FMT=*) I**2
100 CONTINUE
will produce 5 records containing the values 25, 16, 9, 4, and 1
respectively.
Loops can be nested to any reasonable depth. Thus the following statements will set the two dimensional array FIELD to zero.
REAL FIELD(NX, NY)
DO 50, IY = 1,NY
DO 40, IX = 1.NX
FIELD(IX,IY) = 0.0
40 CONTINUE
50 CONTINUE