While Loops in PHP:

Loops are used in PHP to perform same type of execution of code more than one time or for specified time.

In PHP we have two types of while loops:

  • while loop
  • do……while loop

 while loop:

The while loop in PHP will execute the block of code as long as and if the condition is true.

If the condition is true than the code will be executed and than the test condition will be evaluated and than again loop will be continue until the condition is false.



 do…..while loop:

The do…..while loop is same as while loop but the main difference is that the do….while loop execute the code once and than it will check the condition and if the condition is true than it will go ahead and if the condition is false than it will stop execution.



Following example is with true condition


Following example is with false condition


Leave a Reply

Your email address will not be published. Required fields are marked *