The break statement in C language has the following two uses:
1. When the break statement appears within a loop, the loop will terminate immediately, and the program flow will Execution continues with the next statement immediately following the loop.
2. It can be used to terminate a case in a switch statement.
If you are using nested loops (that is, one loop nested within another loop), the break statement will stop execution of the innermost loop and then start execution of the next line of code after the block.
Example:
#include<stdio.h> int main() { /*局部变量定义*/ int a=10; /*while循环执行*/ while(a<20) { printf("a的值:%d\n",a); a++; if(a>15) { /*使用break语句终止循环*/ break; } } return 0; }
When the above code is compiled and executed, it produces the following results:
Value of a: 10
a's value: 11
a's value: 12
a's value: 13
a's value: 14
a's value: 15
Recommended: "c Language Tutorial"
The above is the detailed content of How to use break in c language. For more information, please follow other related articles on the PHP Chinese website!