How Java jumps out of multiple nested loops

Source: Internet
Author: User

Break in Java can jump out of the loop but only jump out of one, Goto this in Java is just as the key is that there is no effect

To jump out of multiple nested loops, you can use this method

Set a flag bit at the beginning of the loop body, set a marker, and then use the break statement with this designator to jump out of multiple loops.

 Public classTest1 { Public Static voidMain (string[] args) {jump://Set a tag to use the break statement with this tag to step out of the multi-loop body                  for(inti=1;i<100;i++){             for(intj=1;j<100;j++){                   for(intk = 0; K < 100; k++) {                          if(i==10){                             BreakJump ; }}} System.out.println ("Run" +i); } System.out.println ("Execution End"); }}

How Java jumps out of multiple nested loops

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.