Home >Backend Development >PHP Tutorial >--In-depth understanding of php42--Revisiting the past

--In-depth understanding of php42--Revisiting the past

WBOY
WBOYOriginal
2016-07-29 08:33:25893browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn