The usage of the break with labels in Java.

Source: Internet
Author: User

Original http://blog.csdn.net/moonwalkings/article/details/4631988

CodeAs follows:

[Java] View plaincopyprint?
  1. Public ClassH
  2. {
  3. Public Static VoidMain (string [] ARGs ){
  4. {
  5. Back:For(IntI =0; I <10; I ++ ){
  6. If(I =9)
  7. {System. Out. println ("Break");
  8. BreakBack;
  9. }
  10. }
  11. System. Out. println ("Test");}
  12. }
  13. }

The appeal code runs as follows:

Break

Test

Another example is code:

[C-sharp] View plaincopyprint?
  1. Public ClassH
  2. {
  3. Public Static VoidMain (string [] ARGs ){
  4. Back :{
  5. For(IntI = 0; I <10; I ++ ){
  6. If(I = 9)
  7. {System.Out. Println ("Break");
  8. BreakBack;
  9. }
  10. }
  11. System.Out. Println ("Test");}
  12. }
  13. }

Public Class H <br/>{< br/> Public static void main (string [] ARGs) {<br/> back: {<br/> for (INT I = 0; I <10; I ++) {<br/> if (I = 9) <br/> {system. out. println ("break"); <br/> Break back; <br/>}< br/> system. out. println ("test") ;}< br/>}< br/>}

 

The running result is:

Break

No test !!

The tagged break is the "airspace" managed by the place indicated by the exit tag, and will not be re-executed from the place indicated by the tag. Therefore, the Appeal code will not start an infinite endless loop from the referred.

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.