当前位置:网站首页>循环结构--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);
}
}
边栏推荐
- Use compilation to realize special effects of love
- How to encapsulate the wx.request() request of WeChat applet
- 3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
- STL中list实现
- Hongxing, donate another million
- wireshark的安装教程(暖气片安装方法图解)
- armv7与armv8的区别(v8和w12的区别)
- LayaBox---TypeScript---Iterator and generator
- LayaBox---TypeScript---JSX
- ConvNeXt论文及实现
猜你喜欢

MSYS2 QtCreator Clangd code analysis can not find mm_malloc.h problem remedy

ConvNeXt论文及实现

享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世

第十五章 多线程

npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.

4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...

Verilog的随机数系统任务----$random

超赞!发现一个APP逆向神器!

向量点积(Dot Product),向量叉积(Cross Product)

迭代器失效问题
随机推荐
DVWA Clearance Log 2 - Command Injection
一款优秀的中文识别库——ocr
yolov7创新点
currentstyle 织梦_dede currentstyle属性完美解决方案
QT专题:事件机制event基础篇
4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...
LayaBox---TypeScript---模块
38岁女儿不恋爱没有稳定工作老母亲愁哭
牛客网项目17节生成验证码 刷新验证码一直没反应
LayaBox---TypeScript---三斜线指令
Verilog的随机数系统任务----$random
LayaBox---TypeScript---Mixins
How to encapsulate the wx.request() request of WeChat applet
Hello, my new name is "Bronze Lock/Tongsuo"
R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
全方位剖析Numpy中的np.diag源代码
2022.7.25-7.31 AI行业周刊(第108期):值钱比赚钱更重要
R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
Pytorch's LSTM parameters explained