package com.example.demo.util;
public class TestWhileAndContinue {
public static void main(String[] args) {
//testWhile();
testContinue();
}
public static void testWhile() {
int i = 0;
while(true){
System.out.println("doing i =" + i);
i++;
if(i == 3){
break;
}
}
}
public static void testContinue() {
boolean flag = true;
int i = 0;
while(true){
if(i == 6){
break;
}
i++;
if(!flag){
System.out.println("i = " + i);
continue;
}
if(i == 2){
flag = false;
}
}
}
}
输出
i = 3
i = 4
i = 5
i = 6