ProgrammingHardTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer s = 0
for (each i from 1 to 10)
    if (i mod 3 == 0) continue
    if (i > 8) break
    s = s + i
end for
Print s
  1. A. 19
  2. B. 28
  3. C. 37
  4. D. 27

Correct answer: D. 27

Added: 1, 2, 4, 5, 7, 8 = 27. Multiples of 3 are skipped, and the loop stops at i = 10 (i = 9 is skipped by continue).

More Pseudocode and Code Tracing questions

Exams that ask this topic