当前位置:网站首页>The difference and usage between continue and break
The difference and usage between continue and break
2022-07-06 05:51:00 【bit..】
generally speaking , After the program enters the loop All statements of the loop body will be executed between the next loop test .continue and break Statement can ignore part of the loop content according to the test results in the loop body , Even the end of the cycle .
continue sentence
All three cycles can be used continue sentence . When the statement is executed , Will skip this iteration ( It's a cycle ) The rest of , And start the next iteration . If continue Statement in nested loop , Only the inner loop containing the statement will be affected .
grammar
C In language continue Sentence syntax :
continue;
flow chart
example
#include <stdio.h>
int main ()
{
/* Definition of local variables */
int a = 10;
/* do Loop execution */
do
{
if( a == 15)
{
/* Skip iteration */
a = a + 1;
continue;
}
printf("a Value : %d\n", a);
a++;
}while( a < 20 );
return 0;
}
When the above code is compiled and executed , It will produce the following results :
a Value : 10
a Value : 11
a Value : 12
a Value : 13
a Value : 14
a Value : 16
a Value : 17
a Value : 18
a Value : 19
break sentence
C In language break Statement has the following two uses :
When break When a statement appears in a loop , The loop ends immediately , And the program flow continues to execute the next statement that follows the loop .
It can be used to terminate switch One of the sentences case.
grammar
C In language break Sentence syntax :
break;
flow chart
example
#include <stdio.h>
int main ()
{
/* Definition of local variables */
int a = 10;
/* while Loop execution */
while( a < 20 )
{
printf("a Value : %d\n", a);
a++;
if( a > 15)
{
/* Use break Statement to terminate the loop */
break;
}
}
return 0;
}
When the above code is compiled and executed , It will produce the following results :
a Value : 10
a Value : 11
a Value : 12
a Value : 13
a Value : 14
a Value : 15
边栏推荐
- SequoiaDB湖仓一体分布式数据库2022.6月刊
- 嵌入式面试题(一:进程与线程)
- Note the various data set acquisition methods of jvxetable
- [C language syntax] the difference between typedef struct and struct
- Embedded interview questions (I: process and thread)
- [Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
- 网络协议模型
- Installation de la Bibliothèque de processus PDK - csmc
- Migrate Infones to stm32
- PDK工藝庫安裝-CSMC
猜你喜欢
Application Security Series 37: log injection
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
What preparations should be made for website server migration?
[Tang Laoshi] C -- encapsulation: classes and objects
The usage and difference between strlen and sizeof
Problems encountered in installing mysql8 on MAC
【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测
B站刘二大人-线性回归及梯度下降
01. Project introduction of blog development project
随机推荐
Application Security Series 37: log injection
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
Embedded interview questions (IV. common algorithms)
查詢生產訂單中某個(些)工作中心對應的標准文本碼
03. Login of development blog project
Yunxiaoduo software internal test distribution test platform description document
[Jiudu OJ 07] folding basket
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
Summary of data sets in intrusion detection field
28io stream, byte output stream writes multiple bytes
MIT6.s081-2020 Lab2 System Calls
[imgui] unity MenuItem shortcut key
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[email protected]树莓派
Deep learning -yolov5 introduction to actual combat click data set training
The usage and difference between strlen and sizeof
[C language syntax] the difference between typedef struct and struct
初识数据库
My 2021