For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

PHP while lopp

Overview

The while loop executes a block of code repeatedly until the condition is FALSE.

Syntax:

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

Example:

$num = 1;
while($num <= 5) {
  	echo "The number is: $num 
"; $num++; }
  • $num = 1; - Initialize the loop counter ($num), and set the start value to 1
  • $num <= 5 - Continue the loop as long as $num is less than or equal to 5
  • $num++; - Increase the loop counter value by 1 for each iteration