0
0
C++programming~20 mins

Jump statement overview in C++ - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Jump Statement Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A11 21 31
B11 21 31 32
C11 12 13 21 22 23 31 32 33
D11 12 21 22 31 32
Attempts:
2 left
💡 Hint
The break statement exits the inner loop when j equals 2.
Predict Output
intermediate
2: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;
}
A1 2 3 4 5
B2 4
C1 3 5
D1 3 4 5
Attempts:
2 left
💡 Hint
Continue skips the rest of the loop body for even numbers.
Predict Output
advanced
2: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;
}
A1 2 3
B0 1 2 3
C0 1
D0 1 2
Attempts:
2 left
💡 Hint
The goto jumps back to the label until count reaches 3.
Predict Output
advanced
2: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;
}
A3
B6
C9
D0
Attempts:
2 left
💡 Hint
Continue skips increment when j equals 1.
Predict Output
expert
2: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;
}
ATwo Three
BTwo
CThree
DDefault
Attempts:
2 left
💡 Hint
Without break after case 2, execution falls through to case 3.