continue
public class RetryTest {
public static void main(String[] args) {
retry:
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
if (j == 2) {
continue retry;
} else {
System.out.println(j);
}
}
}
}
}
编译后的代码:
public class RetryTest {
public RetryTest() {
}
public static void main(String[] args) {
for(int i = 0; i < 2; ++i) {
for(int j = 0; j < 4 && j != 2; ++j) {
System.out.println(j);
}
}
}
}
多加了个判断:
break
public class RetryTest {
public static void main(String[] args) {
retry:
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
if (j == 2) {
break retry;
} else {
System.out.println(j);
}
}
}
}
}
编译后的代码:
public class RetryTest {
public RetryTest() {
}
public static void main(String[] args) {
for(int i = 0; i < 2; ++i) {
for(int j = 0; j < 4; ++j) {
if (j == 2) {
return;
}
System.out.println(j);
}
}
}
}
加了个return