C break Statement
In the C language break statement has the following two uses:
- When break When a statement appears inside a loop, the loop terminates immediately, and program flow continues with the next statement immediately following the loop.
- It can be used to terminate a switch case within a statement.
If you are using nested loops (i.e., one loop inside another), the break statement stops executing the innermost loop and then begins executing the next line of code after that block.
Syntax
In the C language break statement syntax:
break;

Flowchart

Example
Example
#include
int
main
(
)
{
/* Local variable definition */
int
a
=
10
;
/* while loop execution */
while
(
a
<
20
)
{
printf
("Value of a: %d\n"
, a
)
;
a
++
;
if
(
a
15
)
{
/* Use the break statement to terminate the loop */
break
;
}
}
return
0
;
}
When the code above is compiled and executed, it produces the following result:
a 的值: 10
a 的值: 11
a 的值: 12
a 的值: 13
a 的值: 14
a 的值: 15
C Loops