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