分享

java循环中标签的使用

 尹旭东 2012-03-01
package com.newer.test;

/**
 * 标签的使用 <br/>
 * 在循环中使用标签,控制跳转
 * @author xiaoyin
 * @date 2012-3-1下午11:36:07
 */
public class LableTest {
public static void main(String[] args) {
outer: for (int i = 0; true; i++) {
inner: for (int j = 0; true; j++) {
System.out.println("i=" + i + "------j=" + j);
if (j == 1) {
System.out.println("continue");
continue;
}
if (j == 4) {
System.out.println("continue outer");
continue outer;
}
if (j == 6) {
System.out.println("break");
break;
}
if (i == 2) {
if (j == 3) {
System.out.println("continue inner");
j++;
continue inner;
}
}
if (i == 3) {
System.out.println("break outer");
break outer;
}
}
}
}
}

总结:
1. 标签是后面跟有冒号的标识符,例如:label1:
2. 多层循环中可以使用标签跳到指定层
3. while 循环使用标签与 for 循环类似

友情学习:上述如有不对或疑惑之处请您指出,邮箱1870234187@qq.com

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多