Java Foundation Outrageous II: Break keyword

Source: Internet
Author: User

Break in Java is typically used to jump out of a switch or loop.

Jumping out of a switch is basically not a repeat.

Break jumps out of the loop is usually out of the current layer of loops.

If you need to jump out of a multi-layer loop, you can tag after break, and then label the tag until you need to jump out of that layer, which is similar to a goto statement

This may not be very clear, look at the following code is at a glance

 Public classLesson03_1 { Public Static voidMain (string[] args) {lesson03_1 l31=NewLesson03_1 ();        L31.go (); System.exit (0); }     Public voidGo () {String o= ""; Z: for(intx = 0; x < 4; X + +) {zz: for(inty = 0; Y < 2; y++) {                 for(intk = 0; K < 5; k++) {                    if(x = = 1)                         Break; if(x = = 2 && y = = 1)                         BreakZZ; o= O + x +y;    }}} System.out.print (O); }}

When executing to break,just jump out of the last layer of the loop and execute the layer of ZZ

While executing to break zz, it really jumps out of the ZZ Loop and executes the z layer

Java Foundation Outrageous II: Break keyword

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.