zoukankan      html  css  js  c++  java
  • Java break的跳转范围

    public class Worker {
    
        public static boolean sign(int i){
            System.out.print("DoJob
    ");
            return i==4;
        }
    
        public static void main(String[] args) {
            int[] nums = {12, 23, 34, 45, 56, 67, 78, 89, 90};
            firstPoint:for (int i = 0; nums.length > i; i++) {
                System.out.printf("%d
    ", nums[i]);
                judge: if (Worker.sign(i)){
                    System.out.print("goto firstPoint");
                    break firstPoint;
                }else{
                     int j = 0;
                     while (true) {
                        j++;
                        if (j == 3){
                            System.out.print("goto Judge");
                            break judge;
                        }
                    }
                }
                System.out.print("ToEnd
    ");
            }
        }
    
        public void testGoto() {
    
        }
    }

    运行结果:

    12
    DoJob
    goto JudgeToEnd
    23
    DoJob
    goto JudgeToEnd
    34
    DoJob
    goto JudgeToEnd
    45
    DoJob
    goto JudgeToEnd
    56
    DoJob
    goto firstPoint  

    从结果看出,break到judge之后,并不是跳转执行,而是跳转出圈,出哪个圈?break 标签 标注的代码块的圈。

  • 相关阅读:
    UVA
    UVA
    母函数
    快速排序
    集合:set
    stringstream转换
    大学期间的任务
    Devc++贪吃蛇
    Vector容器
    广度优先遍历
  • 原文地址:https://www.cnblogs.com/haiton/p/14470391.html
Copyright © 2011-2022 走看看