Loop label outer usage: Break outer continue outer

Source: Internet
Author: User

1.outer:break

If you do not use a label, break jumps out of the inner for Loop and uses the break label to jump out of the two layer loop

Output: i:0 j:0

i:0 j:1

 Public classBreaktest { Public Static voidMain (string[] args) {outer: for(inti=0; i<10; i++){               for(intj=0; j<10; J + +) {System.out.println ("I:" +i+ "J:" +j); if(j==1){                       Breakouter; }              }          }                }  }  



2.outer:continue

Same as break, using labels, jump out of the 2-layer loop, J value cannot exceed 1

 Public classBreaktest { Public Static voidMain (string[] args) {outer: for(inti=0; i<10; i++){               for(intj=0; j<10; J + +) {System.out.println ("I:" +i+ "J:" +j); if(j==1){                      Continueouter; }              }          }                }    }  

Output:----------running Java programs----------
i:0 j:0
i:0 j:1
I:1 j:0
I:1 j:1
I:2 j:0
I:2 j:1
I:3 j:0
I:3 j:1
I:4 j:0
I:4 j:1
I:5 j:0
I:5 j:1
I:6 j:0
I:6 j:1
I:7 j:0
I:7 j:1
I:8 j:0
I:8 j:1
I:9 j:0
I:9 j:1

Loop label outer usage: Break outer continue outer

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.