[Java Basics] Loop structure 3

Source: Internet
Author: User

[Java Basics] Loop structure 3

Break with continue interrupt loop ...

1 /**2 file path: G:\JavaByHands\ Loop statement3 file name: Breaktest.java4 Write Time: 2016/6/125 Author: Zheng-hui6 Write a description: Break end loop7 Break is completely out of the loop ~ ~ that is, encounter break loop termination ~ ~8 */9 Ten  Public classbreaktest{ One      A      Public Static voidMain (string[] args) { -          -         //write A For loop the          for(inti = 0; I < 10; i + + ) { -              -System.out.println ("i =" +i); -              +             //terminating a loop with break -             //judging the size with = = all wrong many times +             if(i = = 5 ){ A                  at                  Break; -                  -             } -              -         } -          in         //It's good to read more books . -         //use tags to end all loops ... Inside, the outer layer ends together. to         //Outer Loop +         //Add a label - outer: the          for(intj = 0; J < 10; J + +) { *              $             //Inner LoopPanax Notoginseng              for(intk = 0; K < 10; K + +) { -                  theSystem.out.println ("j =" + J + "; k =" +k); +                  A                 //end loop at specified place the                 if(j = = 1 && k = = 5) { +                      -                      Breakouter; $                 } $                  -             } -              the         } -         Wuyi     } the  -}

1 /**2 file path: G:\JavaByHands\ Loop statement3 file name: Continuetest.java4 Write Time: 2016/6/125 Author: Zheng-hui6 Write a note: Continue end this cycle7 Continue is the end of the cycle ~ and then the loop continues ~ ~8 */9 Ten  Public classContinuetest { One      A      Public Static voidMain (string[] args) { -         //Create a loop -          for(inti = 0; I < 10; i + +) { the              -System.out.println ("i =" +i); -              -             //Add a Continue +             if(i = = 5) { -                  +                 Continue; A                  at             } -              -System.out.println ("i + 1 =" + (i + 1)); -              -         } -          in         //Like break , continue can use the label control to end the entire outer layer, the inner loop ~ ~ and then continue ~ -         //label to ABC: +         //outside -          for(intj = 0; J < 3; J + +) { the             //inside *              for(intk = 0; K < 3; K + +) { $System.out.println ("j =" + j + "; K = "+k);Panax Notoginseng                 //conditions -                 if(k = = 2) { the                     ContinueABC; +                 } A                  theSYSTEM.OUT.PRINTLN ("------"); +             } -         }  $          $          -     } -}

[Java Basics] Loop structure 3

Related Article

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.