ProgrammingEasyAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
for (i = 10; i >= 1; i = i - 3)
    Print i
end for
  1. A. 10 7 4 1
  2. B. 10 7 4
  3. C. 10 7 4 1 -2
  4. D. 7 4 1

Correct answer: A. 10 7 4 1

i takes 10, 7, 4, 1; the next value −2 fails i >= 1, so the loop stops. Stopping at 4 treats the condition as i > 1; printing −2 checks the condition after printing.

More Pseudocode and Code Tracing questions

Exams that ask this topic