How to implement a goto-like approach in Java

Source: Internet
Author: User

Goto is a reserved keyword in Java, but this is really useful for beginners to skip this syntax. To improve the reliability and readability of the program, the Java language is now a goto statement that does not support unconditional jumps!!

Fortunately, there is a high imitation jump feature in Java but there is a limitation ( This method is limited to looping nested jumps to the outer loop of the case ) :

Example:

1 As an example:2 Label1:3  for(inti=0;i<n;i++){4      for(intj=0;j<m;j++){5         //......6         ContinueLabel1;//continue to enter for loop after interruption to Label17          BreakLabel1;//interrupts to Label1 but no longer goes into the for loop8     }9}

And also:

How to implement a goto-like approach in Java

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.