ProgrammingModerateTCS Digital · Infosys InfyTQ

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer i, s = 0
for (i = 1; i <= 10; i = i + 1)
    if (i mod 3 == 0)
        continue
    end if
    if (i > 8)
        break
    end if
    s = s + i
end for
Print s
  1. A. 24
  2. B. 45
  3. C. 27
  4. D. 37

Correct answer: C. 27

Added values: 1, 2, 4, 5, 7, 8 (multiples of 3 skipped, loop stops at 10 because 9 is skipped and 10 > 8): total 27.

More Pseudocode and Code Tracing questions

Exams that ask this topic