Learn web design and programming with our free video and text tutorials.
Web Designer? Design and market your own professional website with easy-to-use tools.
PHP do...while loops statements execute a block of code at least once and then it will repeat the loop as long as a condition is true.
<?php
$number=0;
do
{
$number++;
echo "This statement is executed " . $number . " times.<br />";
}
while ($number<10);
?>
The code above outputs:
This statement is executed 1 times.
This statement is executed 2 times.
This statement is executed 3 times.
This statement is executed 4 times.
This statement is executed 5 times.
This statement is executed 6 times.
This statement is executed 7 times.
This statement is executed 8 times.
This statement is executed 9 times.
This statement is executed 10 times.