PHP for loop ?


A for loop is a control statement using which the programmer can give instructions to the computer to execute a set of statement repeatedly as long as specified condition is satisfied. It is required to specify how many times a set of statements have to be executed, it is also called counter controlled loop.


Syntax:-

for (exp 1; exp 2; exp 3)
{
statement…………
}

Q.) W.A.P to print 1 to 5 using for loop.
 <html>
 <body> 
 <?php
 $i;
 for($i = 1; $i <=5 ; $i++)
 { 
 echo $i;
 }
 ?>
 </body>
 </html>
Output
1
2
3
4
5