当前位置:网站首页>Loop structure: while and do while structures
Loop structure: while and do while structures
2022-07-21 19:29:00 【Raise your eyes and look far away】
while loop
1. Grammatical structure
Initial value ;
switch( The loop condition ){
Loop operation code ;
Iteration part ;
}
2. The law of execution :
1) First, execute the initial value code ;
2) Judge cyclic condition , If the cycle condition is true, Is executed {} Loop operation code and iteration code in ,
After iteration , Continue to return to judge the cycle condition , Decide whether to continue the loop operation according to the result of the loop judgment ; If the cycle condition is false, End the whole while Loop structure , Carry on while The code after the loop structure
3. Be careful :
1) The initial value code is executed only once ;
2) No matter how simple or complex it is written , The result can only be Boolean , Either for true Either for false;
3) The function of the iteration part is to change the initial value , Let the cycle condition no longer be satisfied at a certain time , To end the whole while Loop structure .
// Use while Cyclic output 100 Study hard and make progress every day
// Initial value
int i = 1;
while (i <= 100) {// The loop condition i<=100 The loop condition
System.out.println(" The first " + i + " All over : study hard and make progress every day ");// Cyclic operation
i++;// iteration : The purpose of iteration is to change the initial value , In order to be at a certain moment ,
// Let the cycle condition no longer be satisfied , End loop operation , If there is no iteration , The cycle goes into a dead cycle
}
System.out.println(" The program is finished ");
do-while loop
1. Grammatical structure
Initial value
do{
Loop operation code ;
Iteration part ;
}while( The loop condition );
2. The law of execution :
1) First, execute the initial value code
2) Get into {} Execute a loop operation code and iterate part of the code , Judge the condition after execution ,
If the condition is true, return {} Execute loop operation code and iteration part code in ,
If the condition is false, End the whole do-while Loop structure , So let's keep going do-while The code after the loop structure
3. Be careful :
1) The initial value is executed only once ;
2) No matter how simple or complex it is written , The result can only be Boolean , Either for true Either for false;
3)do-while Loop is to execute a loop operation first , In judging cycle conditions , therefore , If the first judgment cycle condition is not satisfied , The loop operation will also be performed once (do-while The loop operation in the loop will be executed at least once )
// Use do-while Cyclic output 1-100 Value
// initialization
int i=1;
do{
System.out.println(" value :"+i);// Cyclic operation
i++;// iteration
}while (i<=100);// The loop condition
while Circulation and do-while loop The difference between :
1) Execution order is different ;
2) When the initial conditions are not met :
while A loop will not execute ;
do-while The loop executes at least once in any case
边栏推荐
- MYSQL06_ Seven join operations and union all of sql99
- 分布式.通用服务层缓存设计
- 使用JPofiler工具分析OOM原因
- 分布式.数据库架构
- 线程池.线程数量设置
- Penetration test - Application of file containing vulnerabilities and PHP pseudo protocol
- Implementation method of SuperMap iclient for openlayers layer group control
- 分布式.高并发&高可用
- Unity - input class
- 分布式.负载均衡
猜你喜欢
紫杉醇联合2-甲氧基雌二醇的白蛋白纳米粒/荜茇酰胺白蛋白纳米粒的研究制备
Loop structure -- while loop and do while loop
Strcspn, strchr special character verification
MYSQL07_ Get date function, aggregate function, string function
List容器的系列操作( 详解 )
分布式.BASE理论
C# 数字信号处理工具包 DSP-Core 重采样(Resample)输出点数是多少
Implementation method of SuperMap iclient for openlayers layer group control
MYSQL09_ Elaborate on database data types
2022 software testing skills jmeter+ant+jenkins continuous integration and test report generation tutorial
随机推荐
List容器的系列操作( 详解 )
Thread pool Thread number setting
Kingbasees v8r6 is there any way to not read sys by default_ System view under catalog?
Arduino I2C for tca9548a response scanner
Software test interview question: in your previous work, what did a software defect (or bug) record contain? How to submit high-quality software bug records?
Distributed Database schema
Metahuman Face材质球总结
Software testing interview question: what is the strategy of software testing?
SAP IDoc tutorial: definition, structure, type, format and table-019
Distributed load balancing
渗透测试-文件包含漏洞以及php伪协议的应用
[QT入门篇]信号槽机制
Create high-performance applications and continuously optimize the user experience
[performance optimization] MySQL common slow query analysis tools
Interview 02
Distributed High concurrency concepts and design goals
Software testing interview question: what is the task of testers in the process of software development?
[qt beginner] timer qtimer class
ClickHouse深度揭秘
分布式.通用服务层缓存设计