do…while循环
- 即使不满足条件至少循环一次
- while 先判断后执行,do while 先执行后判断
package com.struct;
public class DowhileDemo01 {
public static void main(String[] args) {
int a=0;
int sum = 0;
do{
sum=sum+a;
a++;
}while(a<=100);
System.out.println(sum);
}
}
package com.struct;
public class DowhileDemo02 {
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);
}
}