The for loop format is:For ([initialization expression]; [condition expression]; [iteration expression ])
{
// Statement Block
}
Here, the [initialization expression], [condition expression], and [iteration expression] are optional. The [condition expression] must be a Boolean expression.
Perform the following steps:
Step 1: run the initialization expression only once.
Step 2: Start to execute the conditional expression (if it is null, return true). If it is true, execute the statement in braces; if it is false, directly jump to the end point of.
Step 3: start executing the iteration expression + condition expression.
Step 4: if the condition expression is true, execute the statement in braces and return Step 3. If it is false, the control point is switched to the end point of.
Here we will use multiple examples to deepen our understanding:
Example 1:
For (INT num = 1; num <0; num ++)
{
Response. Write (Num );
}
Result: null.
Cause: Execute int num = 1 first, then execute num <0; then num <0 returns false, exit the loop.
Example 2:
Response. Write ("Result: <br/> ");
For (INT num = 1; num <5; ++ num)
{
Response. Write (Num + "<br/> ");
}
In the third part, replace with: num ++ and the result is:
Cause: do not always confuse the I ++ and ++ I problems. Use them here, and do not write something similar to int I = 0; I = I ++; I = ++ I. What is I = I ++? It is equivalent to: int TMP = 0;
I = 1;
I = TMP;
You can write something to confuse yourself.CodeIs it necessary?