Jump to: navigation, search

Php do-while

From w3cyberlearnings

Contents

do-while condition

do-while is similar to while, however in do-while, it executes in the do first before check the expression in the while, and when the expression meets the condition then the statement executes.

Syntax do-while

do
{statement}
while(expre);
 statement

Example 1

<?php
      $count = 4;
         do {
             echo "The count is ". $count . "<br/>";
         }while($count--);

?>
        

Output

The count is 4
The count is 3
The count is 2
The count is 1
The count is 0

Example 2

<?php
// while
    $total = 100;
    while ($total > 200) {
             echo "While display here first 1<br/>";
    }
// do while

    do {
             echo "Will display here first 2 <br/>";
    }
    while($total > 200);
?>
        

Output

Will display here first 2

Related Links


Navigation
Web
SQL
MISC
References