当前位置:网站首页>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
边栏推荐
- 【课程笔记】编译原理
- Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
- Easy to understand IIC protocol explanation
- A master in the field of software architecture -- Reading Notes of the beauty of Architecture
- 初识数据库
- The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
- 数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- Self built DNS server, the client opens the web page slowly, the solution
- 【经验】win11上安装visio
猜你喜欢
26file filter anonymous inner class and lambda optimization
Memory and stack related concepts
[JVM] [Chapter 17] [garbage collector]
[experience] install Visio on win11
Text classification still stays at Bert? The dual contrast learning framework is too strong
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
[SQL Server fast track] - authentication and establishment and management of user accounts
Processes and threads
H3C V7版本交换机配置IRF
什么是独立IP,独立IP主机怎么样?
随机推荐
[Jiudu OJ 08] simple search x
ArcGIS application foundation 4 thematic map making
ARTS Week 25
Improve jpopup to realize dynamic control disable
进程和线程
B站刘二大人-线性回归及梯度下降
Mysql database master-slave cluster construction
[imgui] unity MenuItem shortcut key
[experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
First knowledge database
B站刘二大人-数据集及数据加载 Lecture 8
华为路由器如何配置静态路由
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
01. Project introduction of blog development project
Yygh-11-timing statistics
continue和break的区别与用法
What is independent IP and how about independent IP host?
59. Spiral matrix
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
How can large websites choose better virtual machine service providers?