当前位置:网站首页>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
边栏推荐
- Go language -- language constants
- AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
- Text classification still stays at Bert? The dual contrast learning framework is too strong
- Analysis of grammar elements in turtle Library
- What preparations should be made for website server migration?
- Selective parameters in MATLAB functions
- Station B, Mr. Liu Er - multiple logistic regression, structure 7
- Easy to understand IIC protocol explanation
- LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
- [SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
猜你喜欢

SequoiaDB湖仓一体分布式数据库2022.6月刊

嵌入式面试题(四、常见算法)

Migrate Infones to stm32

Redis message queue

华为BFD的配置规范

What impact will frequent job hopping have on your career?

清除浮动的方式

【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测

Station B Liu Erden linear regression pytoch
[SQL Server fast track] - authentication and establishment and management of user accounts
随机推荐
Promise summary
Classes and objects (I) detailed explanation of this pointer
Self built DNS server, the client opens the web page slowly, the solution
Redis消息队列
[machine learning notes] univariate linear regression principle, formula and code implementation
ARTS Week 25
入侵检测领域数据集总结
59. Spiral matrix
B站刘二大人-反向传播
P2802 go home
Redis message queue
嵌入式面试题(一:进程与线程)
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
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
Closure, decorator
【课程笔记】编译原理
Pay attention to the details of pytoch code, and it is easy to make mistakes
网站进行服务器迁移前应做好哪些准备?
Winter 2021 pat class B problem solution (C language)
B站刘二大人-数据集及数据加载 Lecture 8