Search⌘ K

The break and continue Statements

Explore how break and continue statements alter the flow of loops in C programming. Understand how break exits loops prematurely while continue skips current iterations, helping you write clearer, more efficient control flow in your code.

We'll cover the following...

The break statement

There is a special statement in C called break that allows us to exit from a loop earlier. It overrides the loop condition at the top (or bottom) of the loop, and ‘breaks’ out of the loop.

C
#include <stdio.h>
int main(void) {
// Check whether 80 is in the first 20 multiples of 5
int mult = 0;
for(int i = 1; i <= 20; i++) {
mult = 5 * i;
if( mult == 80 ){
printf("80 is in the first 20 multiples of 5.\n5 x %d = %d\n", i, mult);
break;
printf("The loop does not reach this point\n");
}
}
printf("The loop has ended");
return 0;
}

As you can see in the code above, even though our loop’s ...