For loop is used if you already know how many times your code will be executed.
Syntax
for(init;condition;increment/decrement)
{
statement
}
init - initialization of your variable/counter
condition - test whether the statement is false to be able to continue execution. If true, then the loop stops.
increment/decrement - adds/subtracts a certain value
Let's say you want to display numbers from 1 to 10 using a for loop. The following is the code.
PHP Code
<?php
for ($i=1;$i<=10;$i++)
{
echo $i;
echo "<br>";
}
?>
Output
0 comments:
Post a Comment