Break and continue in Java jump out of a specified loop (reprint)

Source: Internet
Author: User

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)

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.