Break Statement in C

The break statement is used to manipulate program flow in structures such as loops.

When a break statement is executed in a loop, the loop is terminated and program control returns to the next statement following the end of the loop.

The keyword break allows us to do this

Syntax of break statement:

1

break;

The simple code above is the syntax for break statement.

Flowchart of break statement

Example of break Statement

Let’s see the simple example of break statement:

1

2

3

4

5

6

7

8

9

10

#include <stdio.h>

intmain()

{

intx;

for(x=10;x>5;x--){

if(x==7)

break;

}//end for loop

printf("%d\n",x);

}

When you run above program, the output will be following:

1

x = 7

In this program, the condition (x == 7) becomes true after the third iteration. Next, the break statement is executed and program control is sent out from the for loop and continues with the printf() statement.