使用break直接跳出本次循环
public class NestCycle6 {
public static void main(String[] args) {
for(int i = 0; i< 4;i++) {
for(int j = 1; j<=10;j++) {
if(j%4==0) {
break;
}
System.out.print(j+" ");
}
System.out.println();
}
}
}
运行结果:
使用continue直接跳过本次循环
public class NestCycle6 {
public static void main(String[] args) {
for(int i = 0; i< 4;i++) {
for(int j = 1; j<=10;j++) {
if(j%4==0) {
continue;
}
System.out.print(j+" ");
}
System.out.println();
}
}
}
运行结果: