|
In Java, breaks can jump out of the loop but only one, and goto is only regarded as a key in Java, and has no effect This method can be used to break out of multiple nested loops Set a flag bit at the beginning of the loop, set a marker, and then use the break statement with this symbol to jump out of the multiloop.
[mw_shl_code=java,true]public class Test1 { public static void main(String[] args) { JUMP:// set a tag to jump out of the multiloop using a break statement with this tag for(int i=1; i<100; i++){ for(int j=1; j<100; j++){ for (int k = 0; k < 100; k++) { if(i==10){ break JUMP; } } } System.out.println("run" +i); } System.out.println("End of execution"); } }[/mw_shl_code]
|