当前位置:网站首页>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
边栏推荐
- PDK process library installation -csmc
- Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
- JS array list actual use summary
- Station B, Master Liu Er - back propagation
- Rustdesk builds its own remote desktop relay server
- Redis message queue
- Is it difficult for an information system project manager?
- Installation de la Bibliothèque de processus PDK - csmc
- Promise summary
- [SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
猜你喜欢
How to use PHP string query function
PDK process library installation -csmc
[Jiudu OJ 07] folding basket
Novice entry SCM must understand those things
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
What impact will frequent job hopping have on your career?
Is it difficult for an information system project manager?
嵌入式面试题(四、常见算法)
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
RustDesk 搭建一个自己的远程桌面中继服务器
随机推荐
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
My 2021
AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
实践分享:如何安全快速地从 Centos迁移到openEuler
27io stream, byte output stream, OutputStream writes data to file
What impact will frequent job hopping have on your career?
Redistemplate common collection instructions opsforvalue (II)
First knowledge database
Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
59. Spiral matrix
Improve jpopup to realize dynamic control disable
Installation de la Bibliothèque de processus PDK - csmc
[JVM] [Chapter 17] [garbage collector]
[Tang Laoshi] C -- encapsulation: classes and objects
初识数据库
C language learning notes (mind map)
[experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
查询生产订单中某个(些)工作中心对应的标准文本码