PHP - For Loop

The for loop is used when you know in advance how many times the script should run.and for loop is entry control loop like a while loop the following parameters of for loop.

Initialization - used to set a counter.

Condition - Evaluated for each loop iteration.if evaluates to true,the loop continues.if it evaluates to false,the loop end.

Increment & Decrement - used to increment and decrement counter.

Syntax


<?php
for(initialization; condition; increment/decrement)
{
	code to be executed
}
?>						
							

Example


<?php
for($i=1; $i<=10; $i++)
{
	echo $i."
"; } ?>

Output


1
2
3
4
.
.
10							
							
Share Share on Facebook Share on Twitter Share on Google+ Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit