The execution sequence of the for loop.

Source: Internet
Author: User

The execution sequence of the for loop.

Review the basic records and record the execution sequence of this for loop:

For (expression 1; expression 2; expression 3)

{Loop body}

 

Step 1: First assign an initial value to expression 1;

Step 2: Determine whether expression 2 meets the given conditions. If its value is true and the loop condition is met, execute the statement in the loop body, then execute expression 3, and then enter the second loop. If the value of expression 2 is false, The for loop is terminated and the in vitro statement of the loop is executed.

Example 1

Int main (int argc, char * argv []) {for (inti = 0; I <5; I ++) cout <I <"\ t "; return0;}/* He asked hovertree.com */

The output is 0, 1, 2, 3, 4.

 

 

Example 2

Int main (int argc, char * argv []) {int I = 0; for (I = 0; I <5; I ++) cout <I <"\ t"; cout <I <"\ t"; return 0;}/* Ask hovertree.com */

The output is 0, 1, 2, 3, 4, 5.

 

Recommended:

Http://www.cnblogs.com/roucheng/p/cpptimu.html

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.