当前位置:网站首页>循环结构--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);
}
}
边栏推荐
- 斯皮尔曼相关系数
- The R language uses the ggtexttable function of the ggpubr package to visualize the table data (draw the table directly or add the table data to the image), set the theme parameter to customize the fi
- LayaBox---TypeScript---Decorator
- MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
- 软件测试的基本理论知识(软件测试面试基础知识)
- 软件测试X模型
- 软件工程国考总结——选择题
- You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
- iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
- 从测试入门到测试架构师,这10年,他是这样让自己成才的
猜你喜欢

使用较广泛的安全测试工具有哪些?

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

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

软件工程国考总结——选择题

Use compilation to realize special effects of love

Rear tube implements breadcrumb function

周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...

WPF 截图控件之文字(七)「仿微信」

阿里巴巴 CTO 程立:开源是基础软件的源头!

日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
随机推荐
R语言ggplot2可视化:基于aes函数中的fill参数和shape参数自定义绘制分组折线图并添加数据点(散点)、使用theme函数的legend.position函数配置图例到图像右侧
【云原生】快出数量级的性能是怎样炼成的?就提升了亿点点
LayaBox---TypeScript---Iterator and generator
Linux系统卸载,安装,升级,迁移clickHouse数据库
Turning and anti-climbing attack and defense
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the horizontal column chart (bar chart), use the orientation parameter to set the column chart to be tra
开源一夏 | GO语言框架中如何快速集成日志模块
LayaBox---TypeScript---Mixins
DirectX修复工具增强版「建议收藏」
npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
logo 图标(php图片加文字水印)
Verilog的随机数系统任务----$random
零代码工具推荐---HiFlow
软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当
3年测试在职,月薪还不足2w,最近被裁员,用亲身经历给大家提个醒...
适配器模式适配出栈和队列及优先级队列
The R language uses the ggtexttable function of the ggpubr package to visualize the table data (draw the table directly or add the table data to the image), set the theme parameter to customize the fi
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
The realization of the list
The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars