PHP For Loop
Posted by admin on 19 December, 2010
No comments yet
This item was filled under [ PHP & MySql, References ]
The For loop is used to repeat executing a certain code for a specific amount of times. This could as well be done with the while loop however the for loop is made for this. The while loop may be used for much more complex stuff and for various other purposes. The for loop is sorely used for repeating.
for( … declaration …; … condition …; …action… ) {
… execute code …
}
The arguments between brackets are 3: a declaration, a condition and an action. The declaration is usually an integer variable containing a start value, which is usually increased in the action. For example, we could make a for loop which is repeated 10 times:
for($i=1;$i<=10;$i++) {
echo “<p>”.$i.”</p>”;
}
This will result in displaying the numbers 1 through 10.