About Lesson
The while loop executes a block of code repeatedly until the condition is FALSE.
Syntax:
while (condition is true) { code to be executed; }
Example:
$number = 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