Break and continue in Java and tags

Source: Internet
Author: User

I. Break,continue,goto in Java

First break,continue is a keyword in Java, and Goto is a reserved word.

Based on the ghost performance of Goto in C and C + +, I think Goto may still be a long-term bench in Java.

Break: Forcibly exits the loop and does not perform subsequent steps in the loop.

Continue: Launch the current loop, go back to the starting point of the loop, start a new loop

Examples are as follows:

        //ContinueSystem.out.println ("//continue:");  for(inti = 0; I < 10; i++) {            if(i = = 5) {                Continue; } System.out.print ("I=" + i + ""); }        // BreakSystem.out.println ("\n//break:");  for(inti = 0; I < 10; i++) {            if(i = = 5) {                 Break; } System.out.print ("I=" + i + ""); }

The results of the operation are as follows:

Two. labeled Double-loop and Break,continue

For a double-or multilayer-loop break label, it jumps directly to the label and interrupts all loops, while the continue label jumps to the label for a new loop.

Examples are as follows:

Out for(inti = 0; I < 5; i++) {in: for(intj = 0; J < 3; J + +) {                if(i = = 3) {                     BreakOut ; } System.out.println ("I=" + i + "\ T" + "j=" +j); }} System.out.println ("#################################"); Out: for(inti = 0; I < 5; i++) {in: for(intj = 0; J < 3; J + +) {                if(i = = 2) {                    ContinueOut ; } System.out.println ("I=" + i + "\ T" + "j=" +j); }        }

Break and continue in Java and 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.