FORTRAN Reference Manual
Statements
FORTRAN Reference Manual—528615-001
7-29
DO Statement
°
An END statement
•
Nested DO loops
When a DO loop contains another DO loop, the arrangement is called nesting. The 
range of a DO statement can include other DO statements as long as the range of 
each inner DO is entirely within the range of the containing DO statements.
The last statement of an inner DO loop must be either the same as that of its 
containing DO loop or occur before it.
Example A shows nested DO loops that share the same terminal statement. 
Example B shows nested DO loops with different terminal statements:
Example
The following example uses a nested DO loop to calculate the average purchase 
amount in one business day at several store locations:
REAL purchase, sum, average
INTEGER customers
READ (*,*) m
DO 50 j = 1, m
SUM = 0
READ (*,*) customers
DO 25 k = 1, customers
READ (*,*) purchase
sum = sum + purchase
25 CONTINUE
average = sum/customers
PRINT *, 'Average purchase for store', j, '=', 
average
50 CONTINUE
Example A Example B
 DO 5 m = 1,5
.
DO 5 n = 1,10
.
5 CONTINUE
 DO 1 j = 1,10
.
DO 2 k = 2,20,2
.
2 CONTINUE
.
1 CONTINUE










