Software Development Resources
Log in / create account | Log in with OpenID | Help
DocForge is an open peer-reviewed wiki for software developers. Feel free to edit this page. X

PHP/while

From DocForge

< PHP

while and do-while are control flow statements which allow a PHP script to execute a set of statements one or more times based on a condition. While the expression evaluates to true the loop repeats.

[edit] Syntax

while (<expression>) {
    <statements>
}
 
do {
    <statements>
} while (<expression>);

A while loop's expression is evaluated before each loop execution. A do-while's expression is evaluated at the end of the loop. Therefore a do-while is guaranteed to execute at least once.

Discussion

comments powered by Disqus