C/C++ Arena

Step 4 of 6

break and continue

for (int i = 1; i <= 10; i++) {
    if (i % 2 == 0) continue;  // skip even numbers
    if (i > 7) break;          // stop after 7
    printf("%d ", i);
}
// 1 3 5 7

Your turn: read numbers until you see 0. Ignore negative numbers. Print the sum of the positive ones. Use break for the 0 and continue for negatives.

Previous: Accumulating a total Next: do-while