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: 6

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

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.