Log in / create account | Login with OpenID
DocForge
Programmer's Wiki

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.