Bird
Raised Fist0
Cprogramming~20 mins

Break statement in C - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1.

What does the break statement do inside a loop in C?

easy
A. It immediately exits the loop and continues with the code after the loop.
B. It pauses the loop for a moment and then continues.
C. It restarts the loop from the beginning.
D. It skips the current iteration and moves to the next one.

Solution

  1. Step 1: Understand the role of break in loops

    The break statement is designed to stop the loop immediately when executed.
  2. Step 2: Identify what happens after break

    After breaking, the program continues with the first statement after the loop block.
  3. Final Answer:

    It immediately exits the loop and continues with the code after the loop. -> Option A
  4. Quick Check:

    Break stops loop immediately = A [OK]
Hint: Break exits loop immediately, no more iterations [OK]
Common Mistakes:
  • Confusing break with continue
  • Thinking break pauses the loop
  • Assuming break restarts the loop
2.

Which of the following is the correct syntax to use break inside a for loop in C?

for(int i = 0; i < 5; i++) {
    if(i == 3) {
        ?
    }    printf("%d ", i);
}
easy
A. exit;
B. continue;
C. break;
D. stop;

Solution

  1. Step 1: Recall the keyword to exit loops

    In C, break; is the correct statement to exit loops immediately.
  2. Step 2: Check syntax correctness

    Only break; is a valid C keyword; others like exit; or stop; are invalid here.
  3. Final Answer:

    break; -> Option C
  4. Quick Check:

    Correct break syntax = D [OK]
Hint: Use 'break;' to exit loops, not 'exit;' or 'stop;' [OK]
Common Mistakes:
  • Using 'exit;' instead of 'break;'
  • Confusing 'continue;' with 'break;'
  • Missing semicolon after break
3.

What will be the output of the following C code?

int i;
for(i = 0; i < 5; i++) {
    if(i == 2) {
        break;
    }
    printf("%d ", i);
}
medium
A. 0 1
B. 0 1 2
C. 2
D. 0 1 2 3 4

Solution

  1. Step 1: Trace loop iterations until break

    The loop starts i=0, prints 0; i=1, prints 1; when i=2, break triggers and loop stops.
  2. Step 2: Determine printed values

    Only 0 and 1 are printed before break stops the loop.
  3. Final Answer:

    0 1 -> Option A
  4. Quick Check:

    Break at i=2 stops loop, prints 0 1 [OK]
Hint: Break stops loop before printing i=2 [OK]
Common Mistakes:
  • Including value at break condition in output
  • Confusing break with continue
  • Assuming loop runs fully
4.

Identify the error in this C code snippet using break:

int i = 0;
if(i == 0) {
    break;
}
medium
A. Variable i not declared
B. Missing semicolon after break
C. No error, code is correct
D. break used outside loop or switch statement

Solution

  1. Step 1: Check where break is used

    The break statement is inside an if but not inside a loop or switch.
  2. Step 2: Recall break usage rules

    In C, break must be inside loops or switch; using it outside causes a compile error.
  3. Final Answer:

    break used outside loop or switch statement -> Option D
  4. Quick Check:

    Break outside loop/switch = error [OK]
Hint: Break only inside loops or switch [OK]
Common Mistakes:
  • Using break inside if without loop
  • Forgetting break requires semicolon (not the main error here)
  • Assuming break works anywhere
5.

Consider the nested loops below. What will be the output?

for(int i = 1; i <= 3; i++) {
    for(int j = 1; j <= 3; j++) {
        if(j == 2) {
            break;
        }
        printf("%d%d ", i, j);
    }
}
hard
A. 13 12 11
B. 11 21 31
C. 11 12 13 21 22 23 31 32 33
D. 11 12 21 22 31 32

Solution

  1. Step 1: Analyze inner loop behavior with break

    Inner loop runs j=1 to 3, but breaks when j==2, so only j=1 prints.
  2. Step 2: Trace all iterations

    For i=1, prints 11; i=2 prints 21; i=3 prints 31; each inner loop stops after j=1.
  3. Final Answer:

    11 21 31 -> Option B
  4. Quick Check:

    Break stops inner loop at j=2, prints only j=1 per i [OK]
Hint: Break stops inner loop early, only first inner print per outer loop [OK]
Common Mistakes:
  • Assuming inner loop prints all j values
  • Confusing break effect on outer loop
  • Including j=2 prints
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard