Home  >  Article  >  Backend Development  >  Usage of php while statement

Usage of php while statement

藏色散人
藏色散人Original
2020-09-12 09:04:143605browse

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;}].

Usage of php while statement

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn