Do whlie 循环
2024-09-08 17:16:08
Do whlie 循环
◆对于while语句而言,如果不满足条件,则不能进入循环。但有时候我们需要即使不满足条件,也至少执行-次。
◆do...while循环和while循环相似,不同的是,do...while 循环至少会执行一次。
do {
//代码语句
}while(布尔表达式);
◆While和do-While的区别:
◆while先判断后执行。dowhile是 先执行后判断!
◆Do...while总是保证循环体会被至少执行一次! 这是他们的主要差别。
package com.jiemo.struct;
public class DowhileShabi1 {
public static void main(String[] args) {
int i= 0;
int sum =0;
do {
sum=sum+i;
i++;
}while (i<=100);
System.out.println(sum); }}
package com.jiemo.struct;
public class DowhileShabi2 {
public static void main(String[] args) {
int a = 0;
while (a<0){
System.out.println(a);
a++; } System.out.println("_____________________________________________________-");
do {
System.out.println(a);
a++;
}while (a<0); }}
最新文章
- SqlServer游标简介
- MVC学习笔记----缓存
- 批处理脚本为Mysql重置root密码(重置密码为123456)
- sqlserver 解析Json字符串
- Windows 10 Weather App无法正常显示解决方法
- VC2005从开发MFC ActiveX ocx控件到发布到.net网站的全部过程
- Linux高级字符设备驱动
- 【NGUI】屏幕自适应(不用UIStretch,用UIRoot)---------------good
- FastDFS配置过程
- How to hide TabPage from TabControl
- (转)JQuery处理json与ajax返回JSON实例
- Commons Beanutils使用setProperty() - 就是爱Java
- poj2262
- 基于visual Studio2013解决C语言竞赛题之0514单词统计
- MyBatis3入门
- 【C++笔记】析构函数(destructor)
- Luogu P1967 货车运输
- BZOJ.4738.[清华集训2016]汽水(点分治 分数规划)
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习2
- 【大数据】Hive学习笔记