Goto and Break__java in Java

Source: Internet
Author: User

I have recently been asked if there is any goto in Java. The answer is yes. But Java will goto be the most reserved word, and in fact it is not intended to be used in language (as the person thinks).

Then someone will ask, no Goto, that Java is not the interruption of the sentence (narcissism, who will ask you, slag).

NO. NO. NO. Some. The Java designer added a break statement in the language to implement the interrupt program.

Here's a look at two ways to use the break in Java. (Why are two kinds of ...?) ...... Don't tell you now ... Look down ... )。
The first use of break

The code is as follows:

int i = 0;
while (true) {
    if (i = =) {break
        ;
    }
    System.out.printf (i + "");
    i++;
}

Run Result:
0 1 2 3 4 5 6 7 8 9 Break second usage

The code is as follows:

        Jump: for 
        (int i = 0; i < 1000. i++) {for
            (int j = 0; j < 1000; j) {
                System.out.println (j);
                if (j = = ten) {Break Jump}}}
        

Run results
0 1 2 3 4 5 6 7 8 9 10

The above is the two implementations of break in Java. (Have a look at it.) Ha ha ... )

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.