Java中break的作用

1、最常见的作用,跳出Switch语句:

          int k;
                switch(k)
                {
                        case 1:
                        {
                                System.out.println(1);
                        }       break;
                        case 2:
                        {
                                System.out.println(2);
                                break;
                        }
                }

2、跳出语句块:

          first:
                {
                        second:
                        {
                                third:
                                {
                                        for(int i=0;i<3;i++)
                                        {
                                                System.out.println(i);
                                                if(i==2)
                                                {
                                                        break second;
                                                }
                                        }
                                }
                                System.out.println("Second");     //不执行
                        }
                        System.out.println("First");
                }

3、用out标记块,跳出:

<span >              </span>first:
                {
                        out:
                        {
                                third:
                                {
                                        for(int i=0;i<3;i++)
                                        {
                                                System.out.println(i);
                                                if(i==2)
                                                {
                                                        break out;
                                                }
                                        }
                                }
                                System.out.println("out");
                        }
                        System.out.println("First");
                }