This article mainly introduces the PHP process Control do-while, has a certain reference value, now share to everyone, the need for friends can refer to
This paper tries to use the basic Learning Master, please close this page
This article reads 3 minutes, the understanding difficult person is not good to say?
(PHP 4, PHP 5, PHP 7)
The Do-while loop is very similar to the while loop, except that the value of the expression is checked at the end of each loop rather than at the beginning. And the general while loop
The main difference is that the Do-while Loop statement is guaranteed to execute once (the true value of the expression is checked after each loop), but in the general while loop
Not necessarily. (The expression truth value is checked at the beginning of the loop, if the
FALSE
The entire loop is terminated immediately).
The Do-while loop has only one syntax:
<?php$i = 0;do { echo $i;} while ($i > 0);? >
The above loop will run exactly once, because after the first loop, when the true value of the expression is checked, it is FALSE
(not greater than 0) and causes the loop to terminate.
Experienced C users may be familiar with another different do-while loop usage, placing the statement in Do-while (0) and ending the execution loop with a break statement inside the loop. The following code snippet demonstrates this approach:
<?phpdo {if ($i < 5) {echo "I am not big enough"; Break } $i *= $factor; if ($i < $minimum _limit) {break; } echo "I is OK"; /* Process I */} while (0);?