C break Statement
In C languagebreakThe statement has the following two usages:
- WhenbreakWhen the statement appears within a loop, the loop immediately terminates, and program flow continues with the next statement following the loop.
- It can be used to terminateswitchOne case in the statement.
If you are using nested loops (i.e., one loop nested inside another), the break statement stops the execution of the innermost loop and then proceeds to execute the next line of code after that block.
Syntax
In C languagebreakThe syntax of the statement:
break;

Flowchart

Example
Example
#include <stdio.h>
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;
}
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 above code is compiled and executed, it produces the following results:
a 的值: 10 a 的值: 11 a 的值: 12 a 的值: 13 a 的值: 14 a 的值: 15other extensions