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.