The do…while loop example:

<?php

$i = 1;

Do

{

$i++;

echo  $i . “<br>”;

}

while($i <= 3);

?>

Output: 2 3 4

Difference Between while and do…while Loop: With a while loop, the condition to be evaluated is tested at the beginning of each loop statement, so if the conditional expression evaluates to false, the loop will never be executed.

With a do-while loop, on the other hand, the loop will always be executed once, even if the conditional expression is false, because the condition is evaluated at the end of the loop statement.

author image

About admin

You Might Also Like...

Excel Tutorial online
PHP-Insert Data into Mariadb
The FOR Loop

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
YouTube86
YouTube