PHP while Loops

PHP while loops execute a block of code while the specified condition is true.
  • 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

PHP while Loop

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

while (condition is true) {
    code to be executed;
}

PHP do...while Loop

The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.

do 
{
    code to be executed;
} 
while (condition is true);