ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer s = 0
for (i = 1 to 30)
    if (i mod 4 == 0)
        continue
    end if
    if (i mod 7 == 0)
        break
    end if
    s = s + i
end for
Print s
  1. A. 17
  2. B. 21
  3. C. 24
  4. D. 28

Correct answer: A. 17

i = 1, 2, 3 are added (6); i = 4 is skipped by continue; 5 and 6 are added (17); i = 7 triggers break before it is added. s = 17. '21' adds 4 (continue ignored); '24' adds 7 before breaking.

More Pseudocode and Code Tracing questions

Exams that ask this topic