Break and continue in Java jump out of a specified loop
Break and continue in Java can jump out of a specified loop, break and continue do not add any circular name after the default out of the loop, and then specify the loop name, you can jump out of the specified loop (the specified loop is generally a loop nested outer loop).
Break jumps out of the specified loop sample code:
LOOP1:for (int x = 0; x < 4; + +) { loop2:for (int y = 0; y < 5 ; y++ ) { System.out.println ("x=" +x+ ", y=" +y); if (y==2) { break loop1;}} }
Code Run Result:
Continue jumps out of the specified loop sample code:
LOOP1:for (int x = 0; x < 4; + +) { loop2:for (int y = 0; y < 5 ; y++ ) { if (x==2) { continue loop1; } System.out.println ("x=" +x+ ", y=" +y); } }
Code Run Result:
Original address: https://www.cnblogs.com/cowka/p/5977840.html
Break and continue in Java jump out of a specified loop (reprint)