1.1 KiB
title |
---|
Loops |
Loops
Loops are used in PHP to perform repeated tasks based on a condition.
Conditions typically return true
or false
when analysed.
A loop will continue running until the defined condition returns false
.
You can type php for
, php while
or php do while
to get more info on any of these.
PHP Loops
Often when you write code, you want the same block of code to run over and over again in a row. Instead of adding several almost equal code-lines in a script, we can use loops to perform a task like this.
In PHP, we have the following looping statements:
while - loops through a block of code as long as the specified condition is true do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true for - loops through a block of code a specified number of times foreach - loops through a block of code for each element in an array