Loops

Loops repeat a block: for for a known number of iterations, while as long as a condition is true, do while to run at least once, foreach to iterate over a collection. break exits the loop and continue skips to the next iteration. Take care to avoid infinite loops.

Example

for ($i = 0; $i < 3; $i++) {
  echo $i;
}

Related concepts

The whole glossary