- while:先判断,再执行
- for循环:先判断,再执行
- do while :先执行一次,之后再判断
public class Test3 {
public static void main(String[] args) {
Test3 t=new Test3();
t.test1();
t.test2();
t.test3();
}
public void test1() {
int i=0;
for(;i<0;i++){
int s=0;
s+=i;
System.out.println(s);
}
}
public void test2() {
int i=0;
while(i<0){
i++;
int s=0;
s+=i;
System.out.println(s);
}
}
public void test3() {
int i=0;
do{
i++;
int s=0;
s+=i;
System.out.println(s);
}while(i<0);
}
}
只有test3()方法可以运行一次,结果为1,其他两个方法无法输出结果。