Recently want to practice basic work, so take out the Java classic book Think in Java, while learning to remember some of their feelings.
First of all, to say today is the label Label,java reserved goto keyword, but no goto statement. Instead, label. It would have been nice to know this earlier. Looked in the think of Java, to show that learning.
Package com.tudou.t1; /** * Requirements: encountered a situation, when the inner loop has a condition to meet, exit the entire loop * @author LZ * */public class Labelgoto {public static void main (string[) args {test ();//The original method does not satisfy the requirement test1 ()//Original procedure test2 ();//Use label practices} private static void Test () {for (int i = 0; I &l T 10;
i++) {for (int j = 0; J < + j) {if (j = =) {System.out.print ("interrupted");
break;//only interrupts the inner loop} System.out.print (i);
The private static void Test1 () {Boolean flag = false; for (int i = 0; i < i++) {for (int j = 0; J < + j) {if (j = =) {flag = true;//Change the value of the variable S
Ystem.out.println ("interrupted");
Break
} if (flag = = True) {System.out.println ("Variable interrupts outer loop:" + i);
Break }} private static void Test2 () {L://Declare a bookmark for (int i = 0; i < i++) {for (int j = 0; J < 20;
J + +) {if (j = = ten) {System.out.println ("Direct interrupt using label");
Break L;
} System.out.print (i); } System.out.println ("LoopInterrupt.
");
}
}
The first method does not solve the problem, and the second is the most common method we use when we do not have contact with lable.
And after learning the label, found that ... The same as in SQL. I just never knew there were tags in java.