do-while
do-while
loops are very similar to
loops, except the truth expression is
checked at the end of each iteration instead of in the beginning.
The main difference from regular loops is
that the first iteration of a loop is
guaranteed to run (the truth expression is only checked at the end
of the iteration), whereas it may not necessarily run with a
regular loop (the truth expression is
checked at the beginning of each iteration, if it evaluates to
false right from the beginning, the loop
execution would end immediately).
do-while``while``while``do-while``while
There is just one syntax for loops:
`do-while````php
0); ?>
The above loop would run one time exactly, since after the first
iteration, when truth expression is checked, it evaluates to
false ( is not bigger than 0) and the loop
execution ends.
`$i`
Advanced C users may be familiar with a different usage of the
loop, to allow stopping execution in
the middle of code blocks, by encapsulating them with
(0), and using the
statement. The following code fragment demonstrates this:
`do-while``do-while`break```php
<?php
do {
if ($i < 5) {
echo "i is not big enough";
break;
}
$i *= $factor;
if ($i < $minimum_limit) {
break;
}
echo "i is ok";
/* process i */
} while (0);
?>
It is possible to use the
operator instead of this hack. goto