<1-1. break second;> - 위치 주의 

for(조건) second: { ~ }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//================비교1-1)=================
//*
package Ex07.break_continue;
 
public class Ex03_MultiBreak {
    public static void main(String[] args) {
        // ======블럭이 여러개 있는 경우, 원하는 블럭을 나가기위한 break문 만들기=======
        boolean flag = true;
 
        // 식별자: ->ex)first:
        first: {
            
            for(int i=0; i<2; i++) second: {
 
                third: {
                    int k = 100;
                    System.out.println("Before the break");
 
                    if (flag)
                        break second; // second블럭 빠져나가기***
 
                    System.out.println("This won't execute");
 
                } // end third
 
                System.out.println("This is 2 block!!!");
                
                System.out.println(i);
            } // end second
 
            System.out.println("This is after second block");
        } // end first
 
        System.out.println("1234567890");
    }
}
//*/
cs

Before the break
Before the break
This is after second block
1234567890

동작 순서


<1-2.break second;> - 위치 주의

for(조건)  { ~ } 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//================비교1-2)=================
//*
package Ex07.break_continue;
 
public class Ex03_MultiBreak {
    public static void main(String[] args) {
        // ======블럭이 여러개 있는 경우, 원하는 블럭을 나가기위한 break문 만들기=======
        boolean flag = true;
 
        // 식별자: ->ex)firust:
        first: {
 
            second: for (int i = 0; i < 2; i++) {
 
                third: {
                    int k = 100;
                    System.out.println("Before the break");
 
                    if (flag)
                        break second; // second블럭 빠져나가기***
 
                    System.out.println("This won't execute");
 
                } // end third
 
                System.out.println("This is 2 block!!!");
 
                System.out.println(i);
            } // end second
 
            System.out.println("This is after second block");
        } // end firust
 
        System.out.println("1234567890");
    }
}
//*/
cs

Before the break
This is after second block
1234567890

동작 과정

 


<2.break first;>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//================비교2)=================
//*
package Ex07.break_continue;
 
public class Ex03_MultiBreak {
    public static void main(String[] args) {
        // ======블럭이 여러개 있는 경우, 원하는 블럭을 나가기위한 break문 만들기=======
        boolean flag = true;
 
        // 식별자: ->ex)first:
        first: {
            
            for(int i=0; i<2; i++) second: {
 
                third: {
                    int k = 100;
                    System.out.println("Before the break");
 
                    if (flag)
                        break first; // second블럭 빠져나가기***
 
                    System.out.println("This won't execute");
 
                } // end third
 
                System.out.println("This is 2 block!!!");
                
                System.out.println(i);
            } // end second
 
            System.out.println("This is after second block");
        } // end first
 
        System.out.println("1234567890");
    }
}
//*/
cs

Before the break
1234567890

동작 과정

+ Recent posts