Goto__java in the Label,java of the in-JAVA

Source: Internet
Author: User

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.

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.