ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 0
for (each i from 1 to 100)
    if (i mod 4 == 0)
        continue
    end if
    if (i > 10)
        break
    end if
    x = x + i
end for
Print x
  1. A. 43
  2. B. 55
  3. C. 40
  4. D. 45

Correct answer: A. 43

The loop adds 1 to 10 but skips 4 and 8: 55 - 12 = 43. At i = 11 (not a multiple of 4) the break ends the loop, and 12 is never reached.

More Pseudocode and Code Tracing questions

Exams that ask this topic