1.outer:break
If you do not use a label, break jumps out of the inner for Loop and uses the break label to jump out of the two layer loop
Output: i:0 j:0
i:0 j:1
Public classBreaktest { Public Static voidMain (string[] args) {outer: for(inti=0; i<10; i++){ for(intj=0; j<10; J + +) {System.out.println ("I:" +i+ "J:" +j); if(j==1){ Breakouter; } } } } }
2.outer:continue
Same as break, using labels, jump out of the 2-layer loop, J value cannot exceed 1
Public classBreaktest { Public Static voidMain (string[] args) {outer: for(inti=0; i<10; i++){ for(intj=0; j<10; J + +) {System.out.println ("I:" +i+ "J:" +j); if(j==1){ Continueouter; } } } } }
Output:----------running Java programs----------
i:0 j:0
i:0 j:1
I:1 j:0
I:1 j:1
I:2 j:0
I:2 j:1
I:3 j:0
I:3 j:1
I:4 j:0
I:4 j:1
I:5 j:0
I:5 j:1
I:6 j:0
I:6 j:1
I:7 j:0
I:7 j:1
I:8 j:0
I:8 j:1
I:9 j:0
I:9 j:1
Loop label outer usage: Break outer continue outer