The php do…while loop runs the script once and check condition. If the condition is true its stop running and execute the code and it it is false then will repeat the loop until it finds the true condition.
Example
[php]<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 10);
?> [/php]
In the above statement, we have provided $x
variable a value of 1. Then we are running do statement where we are asking script to increment the $x value by one. On the next line, we have mentioned the while statement in which we are asking php script to run the script until the $x
variable reaches to the value 10.
The above will generate following output.
The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
The number is: 10