Break Statement in C (original) (raw)

Last Updated : 17 Oct, 2025

The break statement in C is a loop control statement that breaks out of the loop when encountered. It can be used inside loops or switch statements to bring the control out of the block. The break statement can only break out of a single loop at a time.

C `

#include <stdio.h>

int main() { for (int i = 1; i <= 10; i++) {

      // Exit the loop when i equals 5
    if (i == 5) {
        break;  
    }
    printf("%d ", i);
}
return 0;

}

`

**Explanation: In this program, the break statement exits the loop when i == 5. As a result, the loop stops prematurely, and only the numbers 1 to 4 are printed.

How does break work?

BreakstatementinCforloop

Working of break stateemnt in C

The working of the break statement in C is described below:

Flowchart of break Statement

flowchart-of-break-in-c

Flowchart for Break Statement in C

break with Nested Loops

C `

#include <stdio.h>

int main() {

// Nested for loops with break statement at inner loop
for (int i = 1; i <= 6; ++i)
{
    for (int j = 1; j <= i; ++j)
    {
        if (i <= 4)
        {
            printf("%d ", j);
        }
        else
        {

            // If i > 4 then this innermost loop will break
            break;
        }
    }
    printf("\n");
}
return 0;

}

`

Output

1 1 2 1 2 3 1 2 3 4

**Explanation: In the above program the inner loop breaks when the value of i becomes equal to 4, which stops the printing of the value , although the outer loop continues to run but as the inner loop encounters a break statement for every iteration of i after the value of i becomes equal to 4, no values are printed after the fourth line.

Break in C switch case

#include <stdio.h> #include <stdlib.h>

int main() { char c; float x, y;

while (1)
{
    printf("Enter an operator (+, -), if want to exit "
           "press x: ");
    scanf(" %c", &c);
    // to exit
    if (c == 'x')
        exit(0);

    printf("Enter Two Values:\n ");
    scanf("%f %f", &x, &y);

    switch (c)
    {

    // For Addition
    case '+':
        printf("%.1f + %.1f = %.1f\n", x, y, x + y);
        break;

    // For Subtraction
    case '-':
        printf("%.1f - %.1f = %.1f\n", x, y, x - y);
        break;
    default:
        printf("Error! please write a valid operator\n");
    }
}

}

`

**Output:

Enter an operator (+, -), if want to exit press x: +
Enter Two Values:
10
20
10.0 + 20.0 = 30.0

**Explanation: This C program uses a while loop to repeatedly prompt the user for an operator and two numbers, performing addition or subtraction based on the operator entered. The break statement is used in the switch case to exit after executing the relevant operation, and the program exits when the user enters 'x'. If an invalid operator is provided, an error message is displayed.

break vs continue

The difference between the break and continue in C is listed in the below table:

break continue
The break statement terminates the loop and brings the program control out of the loop. The continue statement terminates only the current iteration and continues with the next iterations.
The syntax is: break; The syntax is: continue;
The break can also be used in switch case. Continue can only be used in loops.