It turns out that there are also tags like goto statements in Java--java label tags

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_6d5354cd0100xjg7.html

——————————————————————————————————————————————————————————————

The hazard of Goto statement:

The goto statement is a jump at the source level, which incurs a bad reputation. If a program always jumps from one place to another, there is still a way to control the process.

"Goto" in Java:

Although the Goto statement in Java is only a reserved word in Java, it has no effect, but I still find the shadow of the goto statement when I use the continue and break statements today. Because both the continue and break statements support jumping to the location of a label. Here are the specific uses:

Inner
for (int i = 0; i<3; i++) {
System.out.println ("iiii===>" +i);
for (int j=0; j<5; J + +) {
if (j = = 1)
Continue inner;
System.out.println ("j===>" +j);
}
}

The output of the above statement is

Iiii===>0
J===>0
Iiii===>1
J===>0
Iiii===>2
J===>0

The general continue statement jumps out of the current loop, but this jumps out to the position of the marker inner. As you can see from this program, when you jump to the label inner you continue with the For loop instead of starting over again.

Ps:

In Java, the only place the label works is before the iteration statement.

The only reason to use tags in Java is because of the existence of nested loops and to break or continue from multiple layers of nesting.

It turns out that there are also tags like goto statements in Java--java label tags

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.