PHP Tutorial
The while statement will execute a block of code if and as long as a test expression is true.
If the test expression is true then the code block will be executed. After the code has executed the test expression will again be evaluated.
while (condition ) {
code to be executed;
}
Condition checks first, and then block of statements executes.
Let's put these syntax into real use.
<?php
$x = 10;
while ($x <= 20){
echo "Number = $x <br>";
$x++;
}
?>
This will produce the following result −
Number = 10
Number = 11
Number = 12
Number = 13
Number = 14
Number = 15
Number = 16
Number = 17
Number = 18
Number = 19
Number = 20