Challenge - 5 Problems
Jump Statement Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of break in nested loops
What is the output of this C++ code snippet?
C++
#include <iostream> int main() { for (int i = 1; i <= 3; ++i) { for (int j = 1; j <= 3; ++j) { if (j == 2) break; std::cout << i << j << " "; } } return 0; }
Attempts:
2 left
💡 Hint
The break statement exits the inner loop when j equals 2.
✗ Incorrect
The inner loop prints when j=1, then breaks when j=2, so only '11', '21', and '31' are printed.
❓ Predict Output
intermediate2:00remaining
Effect of continue in a for loop
What will this C++ code print?
C++
#include <iostream> int main() { for (int i = 1; i <= 5; ++i) { if (i % 2 == 0) continue; std::cout << i << " "; } return 0; }
Attempts:
2 left
💡 Hint
Continue skips the rest of the loop body for even numbers.
✗ Incorrect
The continue statement skips printing when i is even, so only odd numbers 1, 3, and 5 are printed.
❓ Predict Output
advanced2:00remaining
Output of goto with label
What is the output of this C++ program?
C++
#include <iostream> int main() { int count = 0; start: std::cout << count << " "; count++; if (count < 3) goto start; return 0; }
Attempts:
2 left
💡 Hint
The goto jumps back to the label until count reaches 3.
✗ Incorrect
The code prints count starting at 0, increments, and loops until count is 3, printing 0 1 2.
❓ Predict Output
advanced2:00remaining
Value of variable after nested continue
What is the value of variable x after running this code?
C++
#include <iostream> int main() { int x = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (j == 1) continue; x += 1; } } std::cout << x; return 0; }
Attempts:
2 left
💡 Hint
Continue skips increment when j equals 1.
✗ Incorrect
Inner loop runs 3 times per outer loop, but skips when j=1, so increments x twice per outer loop iteration. 3 * 2 = 6.
❓ Predict Output
expert2:00remaining
Output of switch with break and fallthrough
What is the output of this C++ code?
C++
#include <iostream> int main() { int n = 2; switch (n) { case 1: std::cout << "One "; break; case 2: std::cout << "Two "; case 3: std::cout << "Three "; break; default: std::cout << "Default "; } return 0; }
Attempts:
2 left
💡 Hint
Without break after case 2, execution falls through to case 3.
✗ Incorrect
Case 2 prints "Two ", then falls through to case 3 and prints "Three ". Then break stops further execution.