do...while
` loop is another type of loop statement in PHP that is similar to the `while
` loop, but with one important difference. do...while
` loop, the code inside the loop is executed at least once, regardless of whether the condition is true or false. do...while
` loop in PHP is as follows :do {
// code to execute at least once
} while (condition);​
condition
` is an expression that is evaluated after each iteration of the loop. If `condition
` is true, then the code inside the loop is executed again. This process repeats until `condition
` is false.do...while
` loop to print the numbers from 1 to 10 :<?php
// This is a PHP program that uses a do...while loop to print the numbers from 1 to 10
$i = 1;
do {
echo $i . " ";
$i++;
} while ($i <= 10);
?>
1 2 3 4 5 6 7 8 9 10
$i
` is initialized to `1`. The `do...while
` loop then executes the code inside the loop, which prints the value of `$i
`, followed by a space, and increments the value of `$i
` by `1
`.do...while
` loop checks the condition. Since `$i
` has been incremented to `2
`, the condition is still true, and the code inside the loop is executed again. $i
` reaches `11
`, at which point the condition is no longer true, and the `do...while
` loop exits.do...while
` loops can be used to execute a block of code at least once, and then repeatedly as long as a certain condition is true.