For use for loop statements, you know how many times you want to execute a list of statements or statements. This
The For loop is called a clear loop. The syntax in the loop is somewhat complicated, but the loop is often easier than the loop in the
。 The syntax for the For loop is as follows:
for (initialization; condition; increment)
{
code to is executed;
}
The For statement is separated in 3 brackets, and the colon expression is used. When the For loop executes, the following occurs:
The execution of an initialization expression. This expression typically initializes one or more loop counters, but the syntax allows either
How complex the expression is.
The conditional expression is evaluated. If the condition value is true, loop the statement. If the value of the condition is false, the end of the loop
Check.
The expression for this update is executed incrementally.
The execution of the statement, the control returns to step 2.
There is a very simple example of printing out from 0 to 10 numbers:
<?php Tutorial
for ($i =0; $i <=; $i + +)
{
echo "The number is". $i. " <br/> ";
}
?>
The next example is generated to 9 multiplication table 2. The outer loop is responsible for generating a list of dividends, the inner loop will be responsible for producing each number of points
List of frequency converters:
<?php
echo "echo "<table border=2 width=50%";
for ($i = 1; $i <= 9; $i + +) {//this is the outer loop
echo "<tr>";
echo "<td>". $i. " </td> ";
for ($j = 2; $j <= 9; $j + +) {//Inner loop
echo "<td>" $i * $j. " </td> ";
}
echo "</tr>";
}
echo "</table>";
?>
Finally, let's take a look at this example, which uses 2 variables. One to 1 added to all the numbers are 10. The other one adds
into even
<?php
$total = 0;
$even = 0;
for ($x = 1, $y = 1; $x <= $x + +, $y + +) {
if (($y% 2) = = 0) {
$even = $even + $y;
}
$total = $total + $x;
}
echo "The total sum:". $total. " <br/> ";
echo "The sum of even values:". $even;
?>