Logo


PHP Loop While



Loop While

Syntax:

while(condition)
{
// statements that will be executed
}
While loop is used to execute a set of statements repeatedly until a condition becomes false. The loop executes round and round while the condition is true. When the condition becomes false, the loop breaks out or terminates of the loop.

Example

<?php
$num
=1;
 while(
$num<=5)//While the variable ‘num’ is less than or 
               // equal to 5.
  
{
   echo 
$num."<br />";
   
$num++;
  }
 
?>

Output

1
2
3
4
5



If you like this Article, Share and Enjoy



See Also
For Loop
Foreach Loop
Do While Loop