The format for the For loop is:
for (initialization expression; conditional expression; "Iteration representation")
{
Statement block
}
Where: "Initialization expression", "conditional expression", "iteration representation" is optional, and "conditional expression" must be a Boolean expression.
The steps to perform are:
Step one: Start the initialization expression and execute it once.
Step two: Start the conditional expression (return true if null), and if true, execute the statement in curly braces, or false, and skip to the end point for.
Step three: Start the execution of the iteration representation + conditional expression.
Fourth step: If the conditional expression is true, the statement in the curly braces is executed, the third step is returned, and if False, the control point is transferred to the end point for.
Here are a few examples to deepen our understanding:
example one:
for (int num = 1; num < 0; num++)
{
Resp Onse. Write (num);
}
Result: null.
Reason: Perform int num = 1, then num < 0, then num < 0 returns false and exits the loop.
example two:
Response.Write ("Result: <br/>");
for (int num = 1; num < 5; ++num)
{
Response.Write (num + "<br/>"); The third part of
}
is replaced by: num++ The result is also:
Reason: Don't always be confused by the i++,++i problem, use it here, and don't write like int i = 0;i = i ++;i = ++i. i = what is i++? It is equivalent to:
int tmp = 0;
i = 1;
i = tmp;
Do you need to write code that you can all get mixed up with?
current 1/2 page
1 2 Next Read full text