A do-while loop

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.

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/03/31/a-do-while-loop/
YouTube31
YouTube