Skip to content

PHP Do-While Loop

Syntax

The do-while loop in PHP executes the block of code once before checking the condition, ensuring the loop runs at least once.

do {
// Code to execute
} while (condition);

Example

$count = 1;
do {
echo "$count ";
$count++;
} while ($count <= 5);
// Output: 1 2 3 4 5