PHP has a number of built-in looping control structures, such as while
. The basic form of a while
statement is:
while (expr) {
// statements
}
While the expression (expr) evaluates to a truthy value, it will iterate over the statements inside the loop. If the expression (expr) evaluates to false before the first iteration, the statements are never run.
Alternatively you can use a do-while
loop, which runs the statements in the loop once before evaluating the expression (expr).
do {
// statements
} while (expr);