For Loop
Loops is a programming structure that is used to execute one or more commands.
In "for" loop a variable is set to a initial value, there will be a
condition for the loop to continue and an increment operator for the
variable. It will be followed by commands.
The general structure for the "for" loop is
for (condition) { Commnads }
Example
<?php
for ($i=0; $i<6; $i++)
{
echo $i."<BR>";
}
?>
In the above "for" loop the variable i is set to 0, the loop is executed till the condition is met. The variable changes according to the third argument. Each time the commands in brace bracket are executed. Here the echo command uses concatenation operator and thus the outputs are displayed in different lines.
Save the file as forloop.php, upload it to your web server and call in browser to get the result.
Back to Home
|