Java-Tags (label)

Source: Internet
Author: User

In Java, a label must be used before a loop, a loop that is nested within another loop, continue or break from multiple nesting.
Control loops:
1. The continue will return to the beginning of the most inner loop and continue execution;
2. The tagged continue will reach the position of the label and re-enter the loop under the label;
3. Break breaks and jumps out of the current loop;
4. A tagged break breaks the loop that jumps out of the label.

Example of a label for a for loop

//: Main.java/** * For loop label */Class Main { Public Static void Main(string[] args) {intI=0; Outer for(;true;) {inner: for(; i<Ten; i++) {System.out.println ("i ="+ i);if(i==2) {System.out.println ("Continue");Continue; }if(i==3) {System.out.println ("Break"); ++i; Break; }if(i==7) {System.out.println ("Continue outer"); i++;ContinueOuter }if(i==8) {System.out.println ("Break outer"); BreakOuter } for(intk=0; k<5; k++) {if(k==3) {System.out.println ("Continue inner");ContinueInner }                }            }        }    }}/** * output:i = 0 Continue inner i = 1 continue inner i = 2 continue i = 3 break i = 4 continue inner i = 5 continue Inner i = 6 continue inner i = 7 continue outer i = 8 break outer * ///:~

Example of a label for a while loop

//: Main.java/** * While loop tab */Class Main { Public Static void Main(string[] args) {intI=0; Outer while(true) {System.out.println ("Outer while Loop"); while(true) {i++; System.out.println ("i ="+ i);if(i = =1) {System.out.println ("Continue");Continue; }if(i = =3) {System.out.println ("Continue outer");ContinueOuter }if(i = =5) {System.out.println ("Break"); Break; }if(i = =7) {System.out.println ("Break outer"); BreakOuter }            }        }    }}/** * Output:outer while loop i = 1 continue i = 2 I = 3 continue Outer Outer when loop i = 4 i = 5 break Outer Whil E Loop i = 6 i = 7 break outer * ///:~

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java-Tags (label)

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.