FORTRAN computed GO TO: Given JCOKE = 3; JCOKE = JCOKE + 1; GO TO (5, 8, 9, 11, 15, 16, 18, 20) JCOKE. To which statement label is control transferred?
-
A8
-
B11
-
C16
-
D20
-
E9
Answer
Correct Answer: 11
Explanation
Introduction / Context:Classical FORTRAN provides a computed GO TO statement for multi-way branching: GO TO (L1, L2, …, Ln) k transfers control to the k-th label in the list. Understanding the indexing behavior is essential for reading legacy scientific code.
Given Data / Assumptions:
- Initial JCOKE = 3.
- JCOKE is incremented by 1 before the computed GO TO.
- Label list is (5, 8, 9, 11, 15, 16, 18, 20) in that order.
- Indexing is 1-based (k = 1 selects the first label).
Concept / Approach:
Evaluate JCOKE after the increment, then index into the label list. Out-of-range indices typically fall through (implementation dependent), but here the index is within the valid range 1..8.
Step-by-Step Solution:
Start: JCOKE = 3.Execute JCOKE = JCOKE + 1 → JCOKE becomes 4.Computed GO TO picks the 4th label in the list.List positions: 1→5, 2→8, 3→9, 4→11, 5→15, 6→16, 7→18, 8→20.Thus, control transfers to label 11.Verification / Alternative check:
Trace as if it were an array: labels[4] = 11. This matches standard FORTRAN behavior.
Why Other Options Are Wrong:
- 8 and 9: Correspond to indices 2 and 3, not 4.
- 16 and 20: Correspond to indices 6 and 8, respectively.
Common Pitfalls:
Assuming zero-based indexing; forgetting the prior increment of JCOKE; miscounting label positions.
Final Answer:
11