Get the App
SLTechnology News&Howtos  ›  Development  › 

Whether php can use for loop

Shulou Source: shulou.com Published: 2022-06-02 13:29:29 10月02日 Update

This article will explain in detail whether php can use the for loop. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Php can use a for loop, which is used to know in advance how many times a script needs to be run, and its syntax is "for (initial value; condition; increment) {code to be executed;}".

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

PHP cycle-For cycle

Loop the number of times the code block is specified, or loop through the code block when the specified condition is true.

For cycle

The for loop is used when you know in advance how many times the script needs to be run.

Grammar

For (initial value; condition; Increment) {Code to be executed;}

Parameters:

Initial value: mainly initializes a variable value, which is used to set a counter (but it can be any code that is executed once at the beginning of the loop).

Condition: the constraint on the execution of the loop. If TRUE, the loop continues. If FALSE, the loop ends.

Increment: mainly used for incrementing counters (but can be any code that is executed at the end of the loop).

Note: the initial and incremental parameters above can be empty or have multiple expressions (separated by commas).

The following example defines a loop with an initial value of iComple1. As long as the variable I is less than or equal to 5, the loop continues to run. Each time the loop runs, the variable I increments by 1:

Example

Output:

The number is 1, the number is 2, the number is 3, the number is 4, the number is 5.

This is the end of the article on "whether php can use for cycle". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Loops codes numbers conditions increments runs times articles but not parameters variables instances situations more scripts counters syntax facets good practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Shulou Tech Info Huawei Xiaomi