For Loop Execution Process, for loop Process

Source: Internet
Author: User

For Loop Execution Process, for loop Process

Statement format:

For (expression 1; expression 2; expression 3)

{

Loop body

}

Expression 1: Value assignment expression, which is used to assign an initial value to the control variable.

Expression 2: A logical expression is the control condition of a loop. It is used to determine whether the control variable meets the cycle condition. If yes, it enters the loop body. Otherwise, it jumps out of the loop.

Expression 3: A value expression used to increment or decrement control variables.

 For Loop execution steps:

Step 1: Initialize the control variable to determine whether the control variable meets the cycle condition (expression 1-> Expression 2). If yes, it enters the loop body; otherwise, it exits the loop.

Step 2: update the control variable, perform increment or decrement operations on the control variable, and then determine whether the control variable meets the conditions (expression 3-> Expression 2). If the conditions are met, the variable enters the loop body, otherwise, exit the loop.

Step 3: Continue Step 2 until you exit the loop

# Include <stdio. h> int main () {int I; for (I = 0; I <10; I ++) {printf ("% d \ n", I );} printf ("% d \ n", I); return 0 ;}

According to the above analysis, when I does not meet the condition I <10, it jumps out of the loop (that is, when I = 10), so when I is used after jumping out of the loop, I is already 10!

 

Related Article

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.