Search⌘ K

The break and continue Statements

Learn about the break and continue keywords and their usage in the context of loops.

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 ...