Download Java and java Official Website

Source: Internet
Author: User

Download Java and java Official Website

In Java, labels must be used before loops. One loop is nested with the switch of another loop, from multiple nesting to continue or break.
Control Loop:
1. continue will return to the beginning of the innermost loop and continue execution;
2. The continue with tags will arrive at the tag location and re-enter the cycle below the tag;
3. The break is interrupted and jumps out of the current loop;
4. A break with a tag will interrupt the loop that jumps out of the tag.

For Loop label example

//: Main. java/*** for loop label */class Main {public static void main (String [] args) {int I = 0; outer: for (; true;) {inner: for (; I <10; 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 ++; continue outer;} if (I = 8) {System. out. println ("break outer" ); Break outer;} for (int k = 0; k <5; k ++) {if (k = 3) {System. out. println ("continue inner"); continue inner ;}}}}/ *** 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 *///: ~

While loop label example

//: Main. java/*** while LOOP label */class Main {public static void main (String [] args) {int I = 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"); continue outer;} if (I = 5) {System. out. println ("break"); break;} if (I = 7 ){ System. out. println ("break outer"); break outer ;}}}/ *** Output: outer while loop I = 1 continue I = 2 I = 3 continue outer Outer while loop I = 4 I = 5 break Outer while loop I = 6 I = 7 break outer *///: ~

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.