Tag: It increments the learning Loop statement increment for loop structure code
The For loop is the most complex loop structure in PHP. Its behavior is similar to the C language. The number of times to execute the same set of code is used in PHP.
The syntax for the For loop is:
for (EXPR1; expr2; expr3)
Statement
Before I saw the learning video of Qian Feng Education, I have seen such a way of writing:
for ($i =0; $i <=2; $i + +) {
echo $i .& #039;</br> ';
}
$i =0 is the initial value, $i <=2 is the judging condition, $i + + makes the initial value self-increment
In the first loop, $i = 0, which means expression, ($i <= 2), for ture. Therefore, when the print statement executes, the $i gets added 1, which becomes 1.
In the second loop, $ = 1, which means expression, ($i <= 2), for ture. Therefore, when the print statement executes, the $i gets added 1, which becomes 2.
In the third iteration, $i = 2, which means expression, ($i <= 2), for ture. Therefore, when the print statement executes, the $i increments, which becomes 1 3.
In the fourth iteration, $i = 3, which means expression, ($i <= 2), is false. Therefore, PHP does not execute loops and does not execute print statements.
Application of the For loop in PHP 1