Do...While Loop in PHP

do...while loop

It executes a block of code once without checking any conditions and then runs continuously until the condition is satisfied.

Syntax : 

	do
{
//Block of code
}
while( condition )

Example:

<?php

$i = 0;
do
{
    echo $i;
    $i++;
}while($i > 5);

?>


Output for the above code : 0

Explanation : We have initialised our variable $i=0. We have given the condition that $i should be greater than 5. If $i is not greater than 5, it will not continue the loop. But because this is a post tested loop, the loop will run once before checking the condition. So even though $i is not greater than 5 it entered the loop and printed "0" and then the condition does not satisfy, hence it exits the loop.