Continue, break keyword usage for Java

Source: Internet
Author: User

A clear two concepts

    • Loop: Refers to the whole process of repeating an operation in accordance with the specified number of times; its key statements have a for, foreach, while, do, and
    • Iteration: Refers to a single operation during a cycle, 1 cycles consisting of n iterations

Two usage induction

    • Break jumps out of the current loop and ends this loop
    • Continue stops the current iteration and returns to the beginning of the cycle, continuing with the next iteration
    • Break label breaks all iterations and returns to the label, ending all loops currently in progress (both inner and outer loops are terminated)
    • Continue label interrupts all iterations, returns to the label, restarts the next loop from the outer loop

Three examples

 Public classLabeledfor { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        inti = 0; Outer: for(;true; ) {Inner: for(; i < ten; i++) {System.out.println ("I =" +i); if(2 = =i) {System.out.println ("Continue"); //i++;                             Continue; }                         if(3 = =i) {System.out.println ("Break"); I++;  Break; }                         if(7 = =i) {System.out.println ("Continue inner"); I++; Continueouter; }                         if(8 = =i) {System.out.println ("Break Outer");  Breakouter; }}}}} Output result: I= 0I= 1I= 2ContinueI= 3 BreakI= 4I= 5I= 6I= 7ContinueInneri= 8 BreakOuter

Continue, break keyword usage for 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.