//continue使用在循环中,分别是for循环和while循环
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("来输入一个数吧"); //键盘录入嘛~
int x = sc.nextInt();
System.out.println("--------------");
//for循环
for (int i = 1;i <= x ;i++ ) {
if (i == 4) { //循环到4就跳过
continue; //continue
}
System.out.println(i);
}
System.out.println("--------------");
//while循环
int i = 1;
while (i <= x) {
if (i == 4) { //循环到4就跳过
i++;
continue; //continue
}
System.out.println(i);
i++;
}
}
}
请问,while中的continue有没有优化.写了两个 i++...................
|
|