当前位置:网站首页>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
边栏推荐
- 养了只小猫咪
- Practice sharing: how to safely and quickly migrate from CentOS to openeuler
- 05. Security of blog project
- 01. Project introduction of blog development project
- H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
- CoDeSys note 2: set coil and reset coil
- 移植InfoNES到STM32
- [machine learning notes] univariate linear regression principle, formula and code implementation
- Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
- Auto. JS learning notes 17: basic listening events and UI simple click event operations
猜你喜欢

Installation de la Bibliothèque de processus PDK - csmc

华为路由器如何配置静态路由

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

Redis消息队列
![[Tang Laoshi] C -- encapsulation: classes and objects](/img/4e/30d2d4652ea2d4cd5fa7cbbb795863.jpg)
[Tang Laoshi] C -- encapsulation: classes and objects

Construction of yolox based on paste framework

华为BFD的配置规范

H3C防火墙RBM+VRRP 组网配置

Li Chuang EDA learning notes 12: common PCB board layout constraint principles
![[Jiudu OJ 07] folding basket](/img/a7/e394f32cf7f02468988addad67674b.jpg)
[Jiudu OJ 07] folding basket
随机推荐
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
LTE CSFB process
巨杉数据库再次亮相金交会,共建数字经济新时代
Station B, Mr. Liu Er - multiple logistic regression, structure 7
Text classification still stays at Bert? The dual contrast learning framework is too strong
Deep learning -yolov5 introduction to actual combat click data set training
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
03. Login of development blog project
Station B Liu Erden - linear regression and gradient descent
SequoiaDB湖仓一体分布式数据库2022.6月刊
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
ArcGIS application foundation 4 thematic map making
H3C V7版本交换机配置IRF
H3C防火墙RBM+VRRP 组网配置
嵌入式面试题(一:进程与线程)
[email protected]树莓派
B站刘二大人-数据集及数据加载 Lecture 8
My 2021
查詢生產訂單中某個(些)工作中心對應的標准文本碼
Luogu [Beginner Level 4] array p1427 number game of small fish