• Tutorial List

PHP Do While Loop

Last updated May 15, 2020
PHP Do While Loop tutorial

Here you will learn about PHP Do while loop. But, before going further, you must first learn PHP While Loop, because, the do-while loop is very similar to while-loop.

Difference between the Do-While loop and While-Loop

There is only one difference between the do-while loop and the while-loop. The while-loop first checks the condition and then executes the block of code, but the do-while loop first executes the block of code then checks the condition.

Both Loops are executing the block of code according to the condition, but the PHP Do-While loop executes the block of code at least once because it will check the condition after executes the block of code.

How does work the PHP Do-While loop?

How does work the PHP  Do-While loop?

Syntax of Do-While Loop

    // Block of Code

Example of PHP While Loop

The following example displays numbers from 1 to 5.

  $i = 1;
      echo $i.'<br>';
  }while($i <= 5);
Browser Output