<pre name="code" class="java">
<pre name="code" class="java">package breakcontinue;
import java.awt.Label;
import javax.security.auth.kerberos.KerberosKey;
public class Test {
public static void main(String arsg[])
{
xx: for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 5; j++) {
System.out.println("i = " + i + " ,j = " + j);
if (i == 2 && j == 3) {
continue xx; //跳转到xx处,此时i的值是2,然后执行for (int i = 0; i < 10; ++i) i的值变为3,开始新一轮的循环(j从0开始)
}
}
}
System.out.println("\n\n");
yy:
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 5; j++) {
System.out.println("i = " + i + " ,j = " + j);
if (i == 2 && j == 3) {
break yy; //跳转到xx处,但此时不再执行两个for循环,而是直接执行外层for循环正文的代码
}
}
}
System.out.println("out ...");
}
}
输出结果:
i = 0 ,j = 0
i = 0 ,j = 1
i = 0 ,j = 2
i = 0 ,j = 3
i = 0 ,j = 4
i = 1 ,j = 0
i = 1 ,j = 1
i = 1 ,j = 2
i = 1 ,j = 3
i = 1 ,j = 4
i = 2 ,j = 0
i = 2 ,j = 1
i = 2 ,j = 2
i = 2 ,j = 3
i = 3 ,j = 0
i = 3 ,j = 1
i = 3 ,j = 2
i = 3 ,j = 3
i = 3 ,j = 4
i = 0 ,j = 0
i = 0 ,j = 1
i = 0 ,j = 2
i = 0 ,j = 3
i = 0 ,j = 4
i = 1 ,j = 0
i = 1 ,j = 1
i = 1 ,j = 2
i = 1 ,j = 3
i = 1 ,j = 4
i = 2 ,j = 0
i = 2 ,j = 1
i = 2 ,j = 2
i = 2 ,j = 3
out ...