Challenge - 5 Problems
Continue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of loop with continue
What is the output of the following C++ code?
C++
#include <iostream> int main() { for (int i = 1; i <= 5; i++) { if (i == 3) continue; std::cout << i << " "; } return 0; }
Attempts:
2 left
💡 Hint
The continue statement skips the rest of the loop body for the current iteration.
✗ Incorrect
When i equals 3, the continue statement skips printing 3 and moves to the next iteration. So the output excludes 3.
❓ Predict Output
intermediate2:00remaining
Sum with continue skipping multiples of 4
What is the value of sum after running this code?
C++
#include <iostream> int main() { int sum = 0; for (int i = 1; i <= 10; i++) { if (i % 4 == 0) continue; sum += i; } std::cout << sum; return 0; }
Attempts:
2 left
💡 Hint
Numbers divisible by 4 are skipped and not added to sum.
✗ Incorrect
Numbers 4 and 8 are skipped. Sum of 1+2+3+5+6+7+9+10 = 43.
❓ Predict Output
advanced2:00remaining
Nested loops with continue
What is the output of this nested loop code?
C++
#include <iostream> int main() { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (j == 2) continue; std::cout << i << j << " "; } } return 0; }
Attempts:
2 left
💡 Hint
The continue skips printing when j equals 2 inside inner loop.
✗ Incorrect
For each i, j=2 is skipped, so only j=1 and j=3 print. Output is pairs: 11 13 21 23 31 33.
❓ Predict Output
advanced2:00remaining
Continue in while loop
What is the output of this code?
C++
#include <iostream> int main() { int i = 0; while (i < 5) { i++; if (i == 3) continue; std::cout << i << " "; } return 0; }
Attempts:
2 left
💡 Hint
The continue skips printing when i equals 3 after increment.
✗ Incorrect
When i is 3, continue skips printing 3. So output excludes 3.
🧠 Conceptual
expert2:00remaining
Effect of continue on loop variable increment
Consider this code snippet. What will be the output?
C++
#include <iostream> int main() { for (int i = 0; i < 5; ) { i++; if (i == 3) continue; std::cout << i << " "; } return 0; }
Attempts:
2 left
💡 Hint
The increment is inside the loop body before continue.
✗ Incorrect
i is incremented before continue, so when i == 3, continue skips printing 3. Output excludes 3.