PHP do while Loop

The do...while loop – Loops through a block of code once, and then repeats the loop as long as the specified condition is true.

The PHP do…while Loop

The do...while loop will always execute the block of code at least once, it will then check the condition, and repeat the loop while the specified condition is true. Continue reading PHP do while Loop

PHP while Loop

The while loop – Loops through a block of code as long as the specified condition is true

The PHP while Loop

The while loop executes a block of code as long as the specified condition is true.

Example

Print $i as long as $i is less than 6:

$i = 1;
while ($i < 6) {
  echo $i;
  $i++;
}

Note: remember to increment $i, or else the loop will continue forever.

The while loop does not run a specific number of times, but checks after each iteration if the condition is still true.

The condition does not have to be a counter, it could be the status of an operation or any condition that evaluates to either true or false. Continue reading PHP while Loop