Skip to main content

DO versus implied DO loop

Short answer

DO loop repeats a block of statements with a label and CONTINUE. Implied DO is a compact loop inside an I/O list( (item, var=start,end,step)), generating multiple outputs in one statement without labels, and nested implied DO processes the inner index fastest.

Compare DO and implied DO statement in FORTRAN. Explain with suitable example how implied do loop works in FORTRAN.

DO loop

It repeats a block of statements a fixed number of times.

Syntax: DO label var = start, end, step ... label CONTINUE (step is optional and is 1 by default)

      SUM = 0
      DO 10 I = 1, 5
         SUM = SUM + I
   10 CONTINUE

Implied DO

It is a loop written in brackets inside an input/output list (or a DATA statement), without a label or CONTINUE.

Syntax: (list, var = start, end, step)

      INTEGER A(5)
      READ *, (A(I), I = 1, 5)
      PRINT *, (A(I), I = 1, 5)
      PRINT *, (I*I, I = 1, 5)

Comparison

BasisDOImplied DO
PositionA separate statementInside an I/O or DATA list
BodyMany statementsOnly the list items
Label/CONTINUENeeded (old style)Not needed
Main useGeneral repetitionReading or printing arrays
I/O recordsA READ/PRINT inside the loop runs once per pass, so each pass starts a new record (line)A single READ/PRINT handles all the values, so they go on one line

How the implied DO works

The variable is set to the start value and the list items are processed. The variable is then increased by the step and the items are processed again, until the variable passes the end value. For PRINT *, (I*I, I = 1, 5) the values 1, 4, 9, 16, 25 are printed on one line. Implied DOs can be nested: in ((A(I,J), J=1,3), I=1,2) the inner variable J runs fastest, so row 1 is processed first and then row 2.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →