ProgrammingEasyTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 0
for (i = 1 to 10)
    if (i mod 2 == 0) continue
    if (i > 7) break
    a = a + i
end for
Print a
  1. A. 25
  2. B. 9
  3. C. 24
  4. D. 16

Correct answer: D. 16

Even i are skipped by continue; odd i = 1, 3, 5, 7 are added (16); at i = 9 the break ends the loop. Without the break, 9 would be added too (25).

More Pseudocode and Code Tracing questions

Exams that ask this topic