C Break and Continue

C Break and Continue Statements (Beginner → Advanced)
In C Break and Continue are loop control statements.
They change the normal flow of loops (for, while, do-while) and are very important for logic building & interviews.
What is break?
breakimmediately terminates the loop (orswitch) and transfers control outside it.
break in Loop
Output
- Loop stops completely when
i == 3
break in while Loop
Output: 1 2 3
break in switch Statement
- Prevents fall-through
What is continue?
continueskips the current iteration and moves to the next loop iteration.
continue in for Loop
Output
- Only skips when
i == 3
continue in while Loop
Output: 1 2 4 5
- Always update loop variable before
continueto avoid infinite loop
break vs continue (Very Important)
| Feature | break | continue |
|---|---|---|
| Stops loop | Yes | No |
| Skips iteration | No | Yes |
| Used in switch | Yes | No |
| Control goes to | Outside loop | Next iteration |
break / continue in Nested Loops
break (only exits inner loop)
- Only inner loop stops
continue in Nested Loop
- Skips
j == 2only
Real-Life Use Cases
Skip Invalid Data
Stop When Target Found
Used in:
Searching algorithms
Input validation
Menu-driven programs
Embedded loops
Common Mistakes
- Using
continuebefore increment inwhile Expectingcontinueto exit loop- Forgetting
breakinswitch Misusingbreakin nested loops
Interview Questions (Must Prepare)
Difference between
breakandcontinueCan
continuebe used inswitch?What happens if
breakis removed fromswitch?Does
breakexit all loops?Can
continuecause infinite loop?
Summary
breakexits loop completelycontinueskips current iterationbreakworks in loops &switchcontinueworks only in loops- Very important for logic, DSA & interviews
