ProgrammingHardCapgemini · TCS NQT Advanced

What will be the output of the following pseudocode? (continue in a do-while loop goes straight to the while test)

What will be the output of the following pseudocode? (continue in a do-while loop goes straight to the while test)
Integer x = 1, c = 0
do
    x = x * 3
    if (x mod 2 == 1)
        x = x + 1
        continue
    end if
    c = c + 1
while (x < 100)
Print x, c
  1. A. 108 3
  2. B. 122 2
  3. C. 162 4
  4. D. 81 3

Correct answer: A. 108 3

In a do-while, continue jumps to the condition test. x: 3 → odd → 4; 12 (even, c = 1); 36 (c = 2); 108 (c = 3), and 108 ≥ 100 ends the loop. Output 108 3.

More Pseudocode and Code Tracing questions

Exams that ask this topic