For loop execution process

Source: Internet
Author: User

Statement format:

for (expression 1; expression 2; expression 3)

{

Loop body

}

Expression 1: An assignment expression used to assign an initial value to a control variable.

Expression 2: The logical expression is the control condition of the loop, which is used to determine whether the control variable conforms to the cyclic condition, and then enters the loop body, or jumps out of the loop.

Expression 3: An assignment expression used to increment or decrement a control variable.

For loop execution steps:

Step 1: First initialize the control variable, to determine whether the control variable satisfies the loop condition (expression 1-> expression 2), is to enter the loop body, or exit the loop

Step 2: Update the control variables, increment or decrement the control variable operation, and then determine whether the control variable satisfies the condition (expression 3-> expression 2), satisfies the condition enters the loop body, otherwise exits the loop

Step 3: Continue to 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 do not meet the conditions i<10 jump out of the loop (that is, i=10), so after jumping out of the loop in the use of I, I is already 10!

For loop execution process

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.