Home > Article > Backend Development > Usage of php while statement
The while statement in PHP refers to the while loop statement, which is used to repeatedly execute a block of code until the specified condition is not true. Its syntax is [while (condition) {code to be executed;}].
Recommended: "PHP Video Tutorial"
php while loop
The while loop will execute the block of code repeatedly until the specified condition is not true.
Syntax
while (条件) { 要执行的代码; }
Example
The following example first sets the value of variable i to 1 ($i=1;).
Then, the while loop will continue to run as long as i is less than or equal to 5. Each time the loop runs, i will be incremented by 1:
<html> <body> <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br>"; $i++; } ?> </body> </html>
Output:
The number is 1 The number is 2 The number is 3 The number is 4 The number is 5
The above is the detailed content of Usage of php while statement. For more information, please follow other related articles on the PHP Chinese website!