PHP Do While Loop

The block of code executed once and then the condition is evaluated. If the condition is true the statement is repeated as long as the specified condition is true. It executes the code at least one time always because the condition is checked after executing the code.

Syntax

<?php
do {
    code to be executed;
} while (condition is true);
?>

Example

This example sets the $x variable to 7, then it runs the loop, and then the condition is checked:

<?php
$x = 7;

do {
    echo "The number is: $x";
    $x++;
} while ($x <= 5);
?>

On: 01-16-2020