In Fortran 77, consider the loop header: DO 52 N = 1, 10, 3. How many times will this DO loop execute?

Difficulty: Easy

Correct Answer: 4

Explanation:

Introduction / Context:This question checks understanding of Fortran 77 DO loop semantics: initial value, terminal value, and step (increment). Correctly counting iterations prevents off-by-one errors in numerical codes.

Given Data / Assumptions:

  • Loop header: DO 52 N = 1, 10, 3
  • Start N0 = 1; limit NL = 10; step s = 3

Concept / Approach:The loop runs with values N = N0, N0 + s, N0 + 2s, ... while N ≤ NL. Count the generated sequence elements within bounds.

Step-by-Step Solution:

Compute sequence: 1, 1+3 = 4, 4+3 = 7, 7+3 = 10Check bound: 10 ≤ 10 → included; next would be 13 > 10 → stopNumber of values = 4 → executions = 4

Verification / Alternative check:Use count formula for inclusive arithmetic progressions: count = floor((NL - N0)/s) + 1 = floor((10 - 1)/3) + 1 = floor(3) + 1 = 4.

Why Other Options Are Wrong:

  • 1: Ignores subsequent step increments.
  • 10: Mistakes limit for count.
  • 3: Misses inclusion of the terminal value 10.

Common Pitfalls:

  • Off-by-one errors when the last step lands exactly on the limit.
  • Confusing 'step' with 'count'.

Final Answer:4

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion