0
0
Cprogramming~20 mins

Break statement in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Break Statement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of break in a for loop

What is the output of this C code?

C
#include <stdio.h>

int main() {
    for (int i = 0; i < 5; i++) {
        if (i == 3) {
            break;
        }
        printf("%d ", i);
    }
    return 0;
}
A0 1 2 3 4
B0 1 2
C3 4
D0 1 2 3
Attempts:
2 left
💡 Hint

Remember, break stops the loop immediately when the condition is met.

Predict Output
intermediate
2:00remaining
Break inside nested loops

What will be the output of this C program?

C
#include <stdio.h>

int main() {
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++) {
            if (j == 2) {
                break;
            }
            printf("%d%d ", i, j);
        }
    }
    return 0;
}
A11 21 31
B11 12 21 22 31 32
C11 12 13 21 22 23 31 32 33
D13 12 11
Attempts:
2 left
💡 Hint

The break only exits the inner loop when j == 2.

Predict Output
advanced
2:00remaining
Break in while loop with condition

What is the output of this C code?

C
#include <stdio.h>

int main() {
    int count = 0;
    while (count < 10) {
        if (count == 5) {
            break;
        }
        printf("%d ", count);
        count++;
    }
    return 0;
}
A0 1 2 3 4
B0 1 2 3 4 5
C5 6 7 8 9
D0 1 2 3 4 5 6 7 8 9
Attempts:
2 left
💡 Hint

The break stops the loop before printing 5.

Predict Output
advanced
2:00remaining
Break in switch statement

What will be the output of this C program?

C
#include <stdio.h>

int main() {
    int x = 2;
    switch (x) {
        case 1:
            printf("One\n");
            break;
        case 2:
            printf("Two\n");
        case 3:
            printf("Three\n");
            break;
        default:
            printf("Default\n");
    }
    return 0;
}
AThree\n
BTwo\n
CTwo\nThree\n
DDefault\n
Attempts:
2 left
💡 Hint

Without a break after case 2, execution continues to case 3.

Predict Output
expert
2:00remaining
Break effect on multiple nested loops

What is the output of this C program?

C
#include <stdio.h>

int main() {
    int i, j;
    for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 3; j++) {
            if (i * j == 4) {
                break;
            }
            printf("%d%d ", i, j);
        }
    }
    return 0;
}
A11 12 21 22 31
B11 12 21 31 32
C11 12 21 22 31 32
D11 12 13 21 31 32 33
Attempts:
2 left
💡 Hint

The break stops only the inner loop when i * j == 4.