Do-while of PHP Process Control

Source: Internet
Author: User
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

FALSEThe 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);? 

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.