PHP Do While Loop

PHP Do While Loop

PHP do while loop can be used to traverse set of code like php while loop. The PHP do-while loop is guaranteed to run at least once.

It executes the code at least one time always because condition is checked after executing the code.

Syntax :

do
{  
     //code to be executed  
}
while(condition);

Image Source : Zentut


Example

<?php  
$n=1;  
do
{  
    echo "$n<br/>";  
    $n++;  
}while($n<=10);  
?>  
Output :
1
2
3
4
5
6
7
8
9
10