ProgrammingModerateTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer i = 10, c = 0
do
    i = i - 4
    c = c + 1
while (i > 0)
Print i, c
  1. A. 2 2
  2. B. -2 3
  3. C. -2 2
  4. D. 6 3

Correct answer: B. -2 3

i goes 6, 2, -2; the condition is tested after the body, so the loop ends once i = -2 after three passes.

More Pseudocode and Code Tracing questions

Exams that ask this topic