ProgrammingHardAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer c = 0
for (each i from 1 to 3)
    for (each j from 1 to 3)
        if (j == 2)
            break
        end if
        c = c + 1
    end for
end for
Print c
  1. A. 9
  2. B. 6
  3. C. 3
  4. D. 0

Correct answer: C. 3

For every outer i, the inner loop increments c only once (at j=1) before breaking when j reaches 2. With 3 outer iterations, c ends at 3.

More Pseudocode and Code Tracing questions

Exams that ask this topic