当前位置:网站首页>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
边栏推荐
- My 2021
- 28io stream, byte output stream writes multiple bytes
- [C language syntax] the difference between typedef struct and struct
- 大型网站如何选择比较好的云主机服务商?
- 清除浮动的方式
- Zoom through the mouse wheel
- Embedded interview questions (I: process and thread)
- [machine learning notes] univariate linear regression principle, formula and code implementation
- B站刘二大人-数据集及数据加载 Lecture 8
- Web服务连接器:Servlet
猜你喜欢
[JVM] [Chapter 17] [garbage collector]
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
进程和线程
continue和break的区别与用法
网站进行服务器迁移前应做好哪些准备?
Station B, Master Liu Er - dataset and data loading
【经验】win11上安装visio
Hongliao Technology: Liu qiangdong's "heavy hand"
c语言——冒泡排序
随机推荐
ArcGIS application foundation 4 thematic map making
What impact will frequent job hopping have on your career?
How to get list length
Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
Go language -- language constants
26file filter anonymous inner class and lambda optimization
Classes and objects (I) detailed explanation of this pointer
[happy Spring Festival] if you feel happy, dance
什么是独立IP,独立IP主机怎么样?
Is it difficult for an information system project manager?
29io stream, byte output stream continue write line feed
Web Security (V) what is a session? Why do I need a session?
Zoom through the mouse wheel
How can large websites choose better virtual machine service providers?
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
实践分享:如何安全快速地从 Centos迁移到openEuler
Station B Liu Erden - linear regression and gradient descent
Station B Liu Erden softmx classifier and MNIST implementation -structure 9
Redistemplate common collection instructions opsforvalue (II)