C break Keyword
Example
End the loop when i is equal to 4:
int i;
for (i = 0; i < 10; i++) {
if (i == 4) {
break;
}
printf("%d\n", i);
}
Try it Yourself »
Definition and Usage
The break
keyword is used to break out of a
for
loop, a while
loop or a switch
block.
Related Pages
Use the continue
keyword to end the current iteration in a loop, but continue with the next.
Read more about for loops in our C For Loop Tutorial.
Read more about while loops in our C While Loop Tutorial.
Read more about break and continue in our C Break/Continue Tutorial.