The execution sequence of the for Loop in java and the issue of jumping out of multiple loops

Source: Internet
Author: User

Get used to writing for (int ....), I am ashamed to say that I did not think carefully about the sequence of for loop execution at the beginning of my learning. Today I suddenly thought that I checked the information and tried it and figured it out. Java code: for (int I = 0; I <10; I ++) {System. out. println (I);} for Loop execution sequence: 1. in the for loop, run int I = 0; 2. verify I <10; 3. run System. out. println (I); 4. execute I ++; 5. verify I <10; 6. steps 3rd to 5th are repeated. When 7. I = 10, the loop jumps out. Jump out of multiple loops: Java code: outer: for (int I = 1; I <6; I ++) {for (int j = 1; j <6; j ++) {if (I> 1 & I <5) {System. out. println ("*"); // continues the outer loop continue outer; // jumps out of the outermost loop // break outer;} System. out. print (I + "" + j + "");} System. out. println ("");}

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.