Break in Java is typically used to jump out of a switch or loop.
Jumping out of a switch is basically not a repeat.
Break jumps out of the loop is usually out of the current layer of loops.
If you need to jump out of a multi-layer loop, you can tag after break, and then label the tag until you need to jump out of that layer, which is similar to a goto statement
This may not be very clear, look at the following code is at a glance
Public classLesson03_1 { Public Static voidMain (string[] args) {lesson03_1 l31=NewLesson03_1 (); L31.go (); System.exit (0); } Public voidGo () {String o= ""; Z: for(intx = 0; x < 4; X + +) {zz: for(inty = 0; Y < 2; y++) { for(intk = 0; K < 5; k++) { if(x = = 1) Break; if(x = = 2 && y = = 1) BreakZZ; o= O + x +y; }}} System.out.print (O); }}
When executing to break,just jump out of the last layer of the loop and execute the layer of ZZ
While executing to break zz, it really jumps out of the ZZ Loop and executes the z layer
Java Foundation Outrageous II: Break keyword