So, you can understand the "while" loop this way - it executes a series of commands until a specific condition is met. But now let's think about it, what will happen if the first repetition of the condition satisfies the condition? For example, in the repetition above, if you enter 2001, the loop will not execute even once. Try it yourself and you'll see what we mean.
So, if you encounter a repetition that must be executed at least once, you can choose to use the "do-while" loop provided by PHP. First look at the following example:
do
{
do this!
} while (condition)
Let’s do a quick example:
< ?php
$bingo = 366;
while ($bingo == 699)
{
echo "Bingo!";
break;
}
?>
In this case, no matter how many times you run this PHP script, you will not get any output because the value of $bingo is not equal to 699 . However, if you run the following version of the script:
< ?php
$bingo = 799;
do
{
echo "Bingo!";
break;
} while ($bingo == 699);
?> ;
The above has been introduced--In-depth understanding of php42--Revisiting the past, including--. I hope it will be helpful to friends who are interested in PHP tutorials.