Practice mode C++

Assuming standard headers and using namespace std, what does this C++ code print? int s = 0; for (int i = 1; i <= 10; i++) { if (i % 3 == 0) continue; if (i > 7) break; s += i; } cout << s;

Correct answer C. 19

Explanation

The loop skips multiples of 3 with continue, so i = 3 and 6 are never added. At i = 8 the break leaves the loop entirely. The values added are 1, 2, 4, 5 and 7, giving 19. Remember that continue jumps to the next iteration (running i++), while break exits the loop at once.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.