The do-while loop syntax in PHP 8.5 has not changed; it remains fully compatible with previous PHP versions . PHP 8.5 primarily introduces features such as the pipe operator and URI extension, which are unrelated to do-while loops .
Basic Syntax
The basic structure of a do-while loop is as follows:
<?php
do {
// Code to execute
} while (condition);
?>
Key Point: The condition after while must be followed by a semicolon ;. The condition is checked after each loop iteration ends .
Basic Example: Print Numbers 1 to 5
<?php
$i = 1;
do {
echo $i . " ";
$i++;
} while ($i <= 5);
?>
Output
result: 1 2 3 4 5