Php do while loop

Do While loop works same as other programming languages. In the Do while loop, The only difference is that a “do while” loop checks its truth expression before ending each iteration. Basically, this kind of loop makes sure that your statement will run at least once, regardless of the truth expression’s value.

Syntax:-


do
statement
while
(expression);

Example:-


<?php
$x=1;
do{
print $x.'<br/>';
$x++;
} while($x<5)

?>
1
2
3
4

Try it Yourself