ProgrammingModerateTCS NQT · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer s = 0, i = 0
while (i < 10)
    i = i + 1
    if (i mod 3 == 0)
        continue
    end if
    s = s + i
end while
Print s
  1. A. 37
  2. B. 55
  3. C. 18
  4. D. 27

Correct answer: A. 37

i is increased before the test, so continue cannot cause an endless loop. The sum takes 1 to 10 except 3, 6, 9: 55 − 18 = 37.

More Pseudocode and Code Tracing questions

Exams that ask this topic