This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13089|Reply: 0

[Communication] How java jumps out of multiple nested loops

[Copy link]
Posted on 11/10/2014 10:03:45 AM | | | |

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]








Previous:Tomorrow's Double 11 shopping loser's strategy
Next:The mouse connector (powerful) may be used that day, remember to collect it!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com