Home > Backend Development > C#.Net Tutorial > How to use break in c language

How to use break in c language

Release: 2020-03-03 10:45:17
Original
19574 people have browsed it

How to use break in c language

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template