This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Loops

The PHP do...while Loop

The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5

<?php 
// Initialize the loop counter ($x), and set the start value to 1
$x = 1;

do {
  echo "The number is: $x <br>";

// Increase the loop counter value by 1 for each iteration
  $x++;
} 

// Continue the loop as long as $x is less than or equal to 5
while ($x <= 5);
?>

Note: In a do...while loop the condition is tested AFTER executing the statements within the loop. This means that the do...while loop will execute its statements at least once, even if the condition is false. See the next example.