当前位置:网站首页>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
边栏推荐
- LTE CSFB process
- Download, install and use NVM of node, and related use of node and NRM
- c语言——冒泡排序
- B站刘二大人-线性回归 Pytorch
- Improve jpopup to realize dynamic control disable
- 关于 PHP 启动 MongoDb 找不到指定模块问题
- Promise summary
- 26file filter anonymous inner class and lambda optimization
- 应用安全系列之三十七:日志注入
- 27io stream, byte output stream, OutputStream writes data to file
猜你喜欢

05. Security of blog project

【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs

Promise summary

Clear floating mode

Migrate Infones to stm32

wib3.0 跨越,在跨越(ง •̀_•́)ง

B站刘二大人-数据集及数据加载 Lecture 8

RustDesk 搭建一个自己的远程桌面中继服务器

What preparations should be made for website server migration?
随机推荐
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
As3013 fire endurance test of cable distribution system
01. Project introduction of blog development project
Jvxetable implant j-popup with slot
Auto. JS learning notes 17: basic listening events and UI simple click event operations
Summary of data sets in intrusion detection field
Installation de la Bibliothèque de processus PDK - csmc
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
网络协议模型
PDK工艺库安装-CSMC
H3C防火墙RBM+VRRP 组网配置
What is independent IP and how about independent IP host?
P2802 回家
Station B Liu Erden - linear regression and gradient descent
Station B, Master Liu Er - back propagation
ArcGIS应用基础4 专题图的制作
What preparations should be made for website server migration?
Station B, Master Liu Er - dataset and data loading
实践分享:如何安全快速地从 Centos迁移到openEuler
Hongliao Technology: Liu qiangdong's "heavy hand"