Posted By:
16 Mar, 2014 2:52 am PDT

do-while loop in PHP

How to use do-while loop in PHP?

do-while loops is almost same as while loop except the truth expression is checked at the end of each iteration instead of in the beginning. do-while loop is executed atleast once as the condition is checked at the end.

 

//To print the following series using do-while loop.

54321

 

<!DOCTYPE html>

<html>

<body>

<?php

$i=5;

do

 {

echo $i;

     $i--;

}

 while($i>=1);

 ?>

</body>

</html>

 

/*Output of the above program is :

54321

*/

Attachment: doWhile.php


Video tutorial on do-while loop.This illustrate what is do-while loop ,how to use this loop and how it differs from other loops(like while loop etc.).

Was it useful?  




Please login to reply to this problem.