C - Break Statement
Overview
break
exits the nearest enclosing switch
or loop.
Learning Objectives
- Use
break
to terminate loops and switch cases.
Prerequisites
Examples
// break in a loop
for (int i = 0; i < 10; i++) {
if (i == 3) break;
}
// break in switch
switch (op) { case '+': /*...*/ break; default: break; }
Checks for Understanding
- What happens to the loop after
break
executes?
Show answer
Control jumps to the statement after the loop.
Demonstration
#include <stdio.h>
int main(void){
for (int i = 0; i < 10; i++) {
if (i == 3) break;
printf("%d ", i);
}
printf("\n");
}
Expected Output: 0 1 2
Common Pitfalls
break
only exits the innermost loop; outer loops keep running.- In
switch
, missingbreak
causes fallthrough (may be intended or a bug).
Exercises
- Scan an array and break as soon as you find a target value; print its index.
- Read integers until a negative number is entered and then stop.