The break statement is used to exit the current loop or switch statement immediately. The specific functions are: 1. Exit the loop: When it appears in the loop body, it will exit the loop immediately. 2. Exit the switch statement: When it appears in the case branch, exit the switch statement immediately. 3. Labeled break statement: Allows you to exit from a nested structure.
The meaning of break statement in C language
The break statement is a jump statement in C language. Used to immediately exit the currently executing loop or switch statement and transfer control to the code immediately following it.
Usage:
The break statement can be used alone or with optional labels as parameters:
<code class="c">break; // 或 break label;</code>
Function:
Labeled break statement:
The labeled break statement allows you to exit from a nested loop or switch statement. The label must be a valid identifier that appears before the target loop or switch statement in the break statement.
For example:
<code class="c">outer_loop: for (int i = 0; i < 10; i++) { inner_loop: for (int j = 0; j < 5; j++) { if (条件) { break inner_loop; // 退出内层循环 } } }</code>
Common usage:
break statement is usually used in C language for:
The above is the detailed content of The meaning of break in c language. For more information, please follow other related articles on the PHP Chinese website!