Home > Backend Development > PHP Tutorial > Deep understanding of php4(2)--revisiting the past_PHP Tutorial

Deep understanding of php4(2)--revisiting the past_PHP Tutorial

WBOY
Release: 2016-07-21 16:05:14
Original
883 people have browsed it

So, the "while" loop can be understood 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 above repetition, 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);

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315764.htmlTechArticleSo, the while loop can be understood this way - it executes a series of commands until a specific condition is met. But, now let's think about it, if the first repetition of the condition satisfies the condition...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template