PHP 尽管 Loop
这 while
loop - Loops through a block of code as long as the specified condition is true.
The PHP while Loop
这 while
loop executes a block of code as long as the specified condition is true.
句法
while (condition is true) {
code to be executed;
}
例子
The example below displays the numbers from 1 to 5:
示例解释
- $x = 1; - Initialize the loop counter ($x), and set the start value to 1
- $x <= 5 - Continue the loop as long as $x is less than or equal to 5
- $x++; - Increase the loop counter value by 1 for each iteration
此示例以十为单位数到 100:
示例解释
- $x = 0; - 初始化循环计数器 ($x),并将起始值设置为 0
- $x <= 100 - Continue the loop as long as $x is less than or equal to 100
- $x+=10; - Increase the loop counter value by 10 for each iteration