The role of tags in Java

Source: Internet
Author: User

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

"Just before" means that it is not good to place any statements between tags and iterations.

The only reason to set the label before the iteration is that we want to nest another iteration or a switch, because break and continue keywords usually only interrupt the current loop, but if used with the tag, they break the loop until the label is in place

Label1:

outer-iteraction{

inner-itercation{

Break;//1

Continue;//2

Continue LABEL1;//3

Break LABEL1;//4

}

}

In 1, break interrupts the internal iteration, returning to the outer iteration

In 2, continue moves the execution point back to the beginning of the internal iteration

In 3, Contiune Label1 interrupts both internal and external iterations and goes directly to Label1, and then he actually continues the iterative process, but begins with an external iteration

In 4, break Label1 also interrupts all iterations and goes back to Label1, but does not re-enter the iteration, which means that it actually completely aborts two iterations

The role of 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.