当前位置:网站首页>循环结构--while循环
循环结构--while循环
2022-08-02 10:15:00 【白茶清欢*】
一、while循环
1.while循环结构的四个要素
①初始化部分(init_statement)
② 循环条件部分(test_exp)
③循环体部分(boby_statement)
④迭代部分(alter_statement)
①初始化部分
while( ②循环条件部分 ){
③循环体部分 ;
④迭代部分 ;
}
执行过程:① - ② - ③ - ④ - ② - ③ - ④ - ② - ③ - ④ -…- ②
2.while循环说明:
1)写 while 循环千万要小心不要丢了迭代条件。一旦丢了,就可能导致死循环。
2)写程序时要避免死循环。
3)能用 while 循环的,可以用 for 循环,反之亦然。二者可以相互转换。
区别:for 循环和 while 循环的初始化条件部分的作用范围不同,for循环是出了for循环外就不能调用,而while循环出了循环仍能调用.
二、while循环练习
1.遍历100以内的的所有偶数
class WhileTest{
public static void main(String[] args){
int i=0;
while(i<100){
if(i%2==0){
System.out.println(i);
}
i++;
}
//
System.out.println(i);//此处i的值是101,出了while循环也能调用
//*****do-while至少执行一次循环体
int num1=10;
while(num1>10){
System.out.println("hello:while");
num1--;
}
int number2=10;
do{
System.out.println("hello:dowhile");
number--;
}while(number>2);
}
}
边栏推荐
- 程序员的浪漫七夕
- 超赞!发现一个APP逆向神器!
- 8年软件测试工程师的感悟:与薪资相匹配的永远是实力
- 软件测试与质量 之白盒测试
- 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
- You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
- 3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
- 8月份的.NET Conf 活动 专注于 .NET MAUI
- 从测试入门到测试架构师,这10年,他是这样让自己成才的
- 【OpenCV】-霍夫变换
猜你喜欢
DVWA 通关记录 2 - 命令注入 Command Injection
牛客网项目17节生成验证码 刷新验证码一直没反应
npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
一款优秀的中文识别库——ocr
只问耕耘,不问收获,其实收获却在耕耘中
Verilog的随机数系统任务----$random
软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当
牛客刷题——剑指offer(第三期)
games202:三,实时环境光照IBL + PRT
After 21 years of graduation, I switched to software testing. From 0 income to a monthly salary of over 10,000, I am really lucky...
随机推荐
SVN如何删除文件名包含空格的文件
Rear tube implements breadcrumb function
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
currentstyle 织梦_dede currentstyle属性完美解决方案
Hello, my new name is "Bronze Lock/Tongsuo"
php组件漏洞
利用二维数据学习纹理三维网格生成(CVPR 2020)
LayaBox---TypeScript---命名空间和模块
字节跳动软件测试岗,收到offer后我却拒绝了~给面试的人一些忠告....
8月份的.NET Conf 活动 专注于 .NET MAUI
如何选择一块真正“好用的、性能高”的远程控制软件
Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?
行为型模式-模板方法模式
Rust 从入门到精通03-helloworld
周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!
一款优秀的中文识别库——ocr
软件测试与质量 之白盒测试
【术语科普】关于集成工作台那些难懂的词儿,看这篇秒懂!
LayaBox---TypeScript---迭代器和生成器