Tracks
/
PHP
PHP
/
Syllabus
/
While Loops
Wh

While Loops in PHP

0 exercises

About While Loops

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);
Edit via GitHub The link opens in a new window or tab