当前位置:网站首页>循环结构--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);
}
}
边栏推荐
- 21年毕业转行软件测试,从0收入到月薪过万,我真的很幸运...
- 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
- currentstyle 织梦_dede currentstyle属性完美解决方案
- 只问耕耘,不问收获,其实收获却在耕耘中
- QT专题:自定义部件
- Spearman's correlation coefficient
- R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
- 重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
- 食品安全 | 鱼肝油不是鱼油,家有宝宝的注意了
- Geoffery Hinton:深度学习的下一个大事件
猜你喜欢
随机推荐
带你认识40G单纤双向光模块-QSFP+ BiDi光模块
DirectX修复工具增强版「建议收藏」
Verilog's random number system task----$random
Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
斯皮尔曼相关系数
Smoothing of time series data in R language: smoothing time series data to remove noise using the dpill function and locpoly function of the KernSmooth package
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
向量点积(Dot Product),向量叉积(Cross Product)
开源一夏 | GO语言框架中如何快速集成日志模块
3年测试在职,月薪还不足2w,最近被裁员,用亲身经历给大家提个醒...
How to choose a truly "easy-to-use, high-performance" remote control software
一款优秀的中文识别库——ocr
阿里CTO程立:阿里巴巴开源的历程、理念和实践
链表的实现
LayaBox---TypeScript---迭代器和生成器
周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!
WPF 截图控件之文字(七)「仿微信」
为什么要使用BGP?
STL中list实现
未知内容监控









