PHP do While loop statement tutorial

Source: Internet
Author: User

There is a certain difference between the PHP do While loop statement and the while, and the difference is that the do is executed first, regardless of whether the condition is true, while the while must be true.

A "dol while" loop is a while loop that modifies the version slightly. If you recal from a previous experience although the cyclic conditional statement is checked back in real code then executes in the while loop. If a conditional declaration is false the code is then not executed within the loop.


On the other hand, doing so, the while loop always executes its code block at least once. This is because conditional declarations are not checked before the code is loaded and is executed.

PHP's-while and not-looping comparisons, while
A simple example of the difference between the two loop types is a conditional declaration that is always false. First, the While loop

$cookies = 0;
while ($cookies > 1) {
echo "Mmmmm ... I Love cookies! *munch Munch munch* ";
}

No output.

Let me take a look at the doing while statement.

$cookies = 0;
do {
echo "Mmmmm ... I Love cookies! *munch Munch munch* ";
while ($cookies > 1);

The output is.

Mmmmm ... I Love cookies! *munch Munch Munch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.