ProgrammingModerateTCS NQT · Infosys pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer c = 0
for (i = 1 to 4)
    for (j = 1 to 4)
        if (j > i)
            break
        end if
        c = c + j
    end for
end for
Print c
  1. A. 40
  2. B. 10
  3. C. 16
  4. D. 20

Correct answer: D. 20

break leaves only the INNER loop, so for each i, j runs 1..i: sums 1, 1+2 = 3, 6, 10 → total 20. '10' stops everything at the first break; '40' ignores the break (4 × 10).

More Pseudocode and Code Tracing questions

Exams that ask this topic