Home>Article>Backend Development> What does break mean in c language?

What does break mean in c language?

烟雨青岚
烟雨青岚 Original
2020-06-11 10:24:43 52779browse

What does break mean in c language?

breakis a reserved word in some computer languages. Its function is to terminate the loop of the previous level in most cases. In C language, break is in switch (Switch statement) The role of jumping out of the statement after executing a case.

1. Break in C language:

The break statement is usually used in loop statements and switch statements. When break is used in the switch statement switch, the program can jump out of the switch and execute the statements after the switch; if there is no break statement, it will become an infinite loop and cannot exit.

When the break statement is used in do-while, for, while loop statements, the program can terminate the loop and execute the statements following the loop. Usually the break statement is always combined with the if statement. That is, when the conditions are met, the loop will be jumped out.

2. Break usage scenarios:

(1) in while loop

if(条件判断) break;---------------------------------------->退出当前循环结构(结束while循环)

(2) in for loop

for(条件) if(条件判断) break;---------------------------------->退出当前循环结构(结束for循环)

(3) switch statement

switch(开关) case 开关值: break;--------------------------------------->退出当前switch语句(结束switch语句) ... ... default: break;

Push tutorial: "C Language"

The above is the detailed content of What does break mean in c language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn