➤ The while loop executes a block of code as long as the specified condition is true.
while (condition is true) {
code to be executed;
}
For instance:
// outputs the numbers from 1 to 10
$x = 1;
while($x <= 10) {
echo "The number is: $x \n";
$x++;
}
// $x = 1; - Initialize the loop counter ($x), and set the start value to 1
// $x <= 10 - Continue the loop as long as $x is less than or equal to 5
/* $x++; - Increase the loop counter value by 1 for each iteration.
Otherwise, the condition always will be true and the loop will run endlessly*/