Use of Java:label (while loop)

Source: Internet
Author: User

1  Packagejava_test;2 3  Public classLabelwhile {4 5      Public Static voidMain (string[] args) {6         inti = 0;7Outer while(true) {8System.out.println ("Outer while Loop");9              while(true) {Teni++; OneSystem.out.println ("i=" +i); A                 if(i = = 1) { -System.out.println ("Continue"); -                     Continue; the                 } -                 if(i = = 3) { -SYSTEM.OUT.PRINTLN ("Continue outer"); -                     Continueouter; +                 } -                 if(i = = 5) { +System.out.println ("Break"); A                      Break; at                 } -                 if(i = = 7) { -SYSTEM.OUT.PRINTLN ("Break outer"); -                      Breakouter; -                 } -             } in         } -     } to}

Output

1Outer whileLoop2I= 13 Continue4I= 25I= 36 Continueouter7Outer whileLoop8I= 49I= 5Ten  Break OneOuter whileLoop AI= 6 -I= 7 -  BreakOuter

It is important to remember, the only reason to use labels in Java are when you have nested loops and we want to break or continue throught more of the one nested level.

Use of Java:label (while loop)

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.