C Break and Continue

C Tutorial

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?

break immediately terminates the loop (or switch) and transfers control outside it.


break in Loop


 

Output

1 2
  •  Loop stops completely when i == 3

break in while Loop

Output: 1 2 3


break in switch Statement


 

  •  Prevents fall-through

 What is continue?

continue skips the current iteration and moves to the next loop iteration.


continue in for Loop


 

Output

1 2 4 5
  •  Only skips when i == 3

continue in while Loop

 Output: 1 2 4 5

  • Always update loop variable before continue to avoid infinite loop

break vs continue (Very Important)

Featurebreakcontinue
Stops loop Yes No
Skips iteration No Yes
Used in switch YesNo
Control goes toOutside loopNext iteration

break / continue in Nested Loops

break (only exits inner loop)

  •  Only inner loop stops

continue in Nested Loop

  •  Skips j == 2 only

 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 continue before increment in while
  •  Expecting continue to exit loop
  •  Forgetting break in switch
  •  Misusing break in nested loops

 Interview Questions (Must Prepare)

  1. Difference between break and continue

  2. Can continue be used in switch?

  3. What happens if break is removed from switch?

  4. Does break exit all loops?

  5. Can continue cause infinite loop?


 Summary

  • break exits loop completely
  • continue skips current iteration
  • break works in loops & switch
  •  continue works only in loops
  •  Very important for logic, DSA & interviews

You may also like...