while
` loop is a type of loop statement in PHP that allows you to execute a block of code repeatedly as long as a certain condition is true. while
` loop in PHP is as follows :while (condition) {
// code to execute while condition is true
}​
condition
` is an expression that is evaluated before each iteration of the loop. If `condition
` is true, then the code inside the loop is executed. After the code inside the loop is executed, the `condition
` is evaluated again, and the loop continues as long as `condition
` is true.while
` loop to print the numbers from 1 to 10 :<?php
// This is a PHP program that uses a while loop to print the numbers from 1 to 10
$i = 1;
while ($i <= 10) {
echo $i . " ";
$i++;
}
?>
1 2 3 4 5 6 7 8 9 10
$i
` is initialized to `1
`. The `while
` loop then checks if `$i
` is less than or equal to `10
`. Since `$i
` starts out as `1
`, the condition is true, and the code inside the loop is executed. echo
` statement prints the value of `$i
`, followed by a space. The `$i++
` statement increments the value of `$i
` by `1
`.while
` loop checks the condition again. Since `$i
` has been incremented to `2
`, the condition is still true, and the code inside the loop is executed again. This process repeats until `$i
` reaches `11
`, at which point the condition is no longer true, and the `while
` loop exits.while
` loops can be used to execute a block of code repeatedly as long as a certain condition is true.