- Asked 3/16
- 2072 Chaitra · 3 marks
- 2072 Kartik · 4 marks
- 2069 Asar · 1+1 marks
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
| Basis | DO | Implied DO |
|---|---|---|
| Position | A separate statement | Inside an I/O or DATA list |
| Body | Many statements | Only the list items |
| Label/CONTINUE | Needed (old style) | Not needed |
| Main use | General repetition | Reading or printing arrays |
| I/O records | A 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)
Related questions
- High level languages; C versus FORTRAN · Computer Programming, chapter 1
- Formatted I/O in FORTRAN with syntax · Computer Programming, chapter 11
- Arithmetic versus logical IF · Computer Programming, chapter 11 · asked 3×
- Break versus continue · Computer Programming, chapter 5 · asked 3×
- do...while versus for/while loops · Computer Programming, chapter 5 · asked 2×
- Open loop versus closed loop control · Embedded System, chapter 7 · asked 6×
- Why closed loop response is faster than open loop · Control Systems, chapter 1 · asked 4×
- T/F: loop arrangement in urban area economical · Transmission and Distribution System Design, chapter 5
- True/false: air conditioner is closed loop · Control Systems, chapter 1