当前位置:网站首页>循环结构--do-while循环
循环结构--do-while循环
2022-08-02 10:15:00 【白茶清欢*】
一、do-while循环
1.、循环结构的四个要素
① 初始化条件
② 循环条件 —> 是 boolean 类型
③ 循环体
④ 迭代条件
2.、do-while 循环的结构
①
do{
③ ;
④ ;
}while( ② );
3、执行过程:① - ③ - ④ - ② - ① - ③ - ④ - … - ②
4、说明:do-while 循环至少执行一次循环体。
1)不在循环条件部分限制次数的结构:
while(true) , for(true)
2)结束循环的几种方式:
方式一:循环条件部分返回 false;
方式二:在循环体中,执行 break;
二、do-while循环练习
1.遍历100以内的偶数,并计算所有偶数的和及偶数的个数
class DoWhileTest{
public static void main(String[] args){
int num=1;
int sum=0;//记录总和
int count=0;//记录个数
do{
if(num%2==0){
System.out.println(num);
sum+=num;
count++;
}
num++;
}while(num<=100);
System.out.println("总和为:"+sum);
System.out.println("总和为:"+count);
}
}
边栏推荐
- R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、设置theme主题参数自定义表格中表头内容的填充色(使用colnames.style参数)
- Facebook's automated data analysis solution saves worry and effort in advertising
- c#反射和特性
- LayaBox---TypeScript---三斜线指令
- games202:三,实时环境光照IBL + PRT
- Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
- Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
- R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha
- logo 图标(php图片加文字水印)
- LayaBox---TypeScript---JSX
猜你喜欢
软件工程国考总结——选择题
瑞萨RZ/G2L处理器详细测评
神通数据库,批量插入数据的时候失败
Use compilation to realize special effects of love
Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
WPF 截图控件之文字(七)「仿微信」
软件测试与质量 之白盒测试
yolov7创新点
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
随机推荐
Verilog的随机数系统任务----$random
众城优选系统开发功能
第十五章 多线程
How to choose a truly "easy-to-use, high-performance" remote control software
yolov7 innovation point
Getting Started with SCM from Scratch (1): Summary of Background Knowledge
Supervised learning of Li Hang's "Statistical Learning Methods" Notes
软件工程国考总结——选择题
Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
练习-17
带你认识40G单纤双向光模块-QSFP+ BiDi光模块
php组件漏洞
食品安全 | 鱼肝油不是鱼油,家有宝宝的注意了
Unknown content monitoring
软件测试的基本理论知识(软件测试面试基础知识)
One Summer of Open Source | How to Quickly Integrate Log Modules in GO Language Framework
链表的实现
R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚