Java中带标签的break、continue

<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 ...



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值