close[x]


PHP

PHP-Home PHP-Environment Setup PHP-Syntax PHP-Run PHP in XAMPP PHP-Variable PHP-Comment PHP-Datatype PHP-String PHP-Operators PHP-Decision PHP-loop PHP-Get/Post PHP-Do While loop PHP-While loop PHP-For loop PHP-Foreach loop PHP-Array PHP-Multidimensional Arrays PHP-Associative Arrays PHP-Indexed Arrays PHP-Function PHP-Cookies. PHP-Session PHP-File upload PHP-Email PHP-Data & Time PHP-Include & Require PHP-Error PHP-File I/O PHP-Read File PHP-Write File PHP-Append & Delete File PHP-Filter PHP-Form Validation PHP-MySQl PHP-XML PHP-AJAX



learncodehere.com




PHP - do...while Loop

The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.

It executes the code at least one time always because the condition is checked after executing the code.

Syntax : do...while Loop


do {
  code to be executed;
} while (condition is true);

In a do...while loop the condition is tested AFTER executing the statements within the loop.

Let's put these syntax into real use.

Example : foreach Loop


<?php 
$x = 10; 
do {
 echo "Number = $x <br>";
 $x++;
} while ($x <= 20);
?>
    

This will produce the following result −

Result


 Number = 10
 Number = 11
 Number = 12
 Number = 13
 Number = 14
 Number = 15
 Number = 16
 Number = 17
 Number = 18
 Number = 19
 Number = 20