Break and Continue Statements
Break and Continue Statements
The break and continue statements are control flow statements in C that alter the normal flow of
a loop. These statements allow greater flexibility in managing loop execution.
. 1. break Statement
The break statement is used to exit from a loop or switch statement prematurely. When a break is
encountered, the control exits the current loop or switch block and moves to the first statement
following the loop or switch.
Syntax: break;
How It Works
Examples
#include <stdio.h>
int main() {
if (i == 5) {
printf("%d\n", i);
return 0;
}
Output: 1
#include <stdio.h>
int main() {
int i = 1;
if (i == 5) {
printf("%d\n", i);
i++;
return 0;
Output: 1
3
4
#include <stdio.h>
int main() {
int num = 2;
switch (num) {
case 1:
printf("Case 1\n");
break;
case 2:
printf("Case 2\n");
case 3:
printf("Case 3\n");
break;
default:
printf("Default case\n");
return 0;
Output: Case 2