Simple php for loop instance, phpfor loop instance

Source: Internet
Author: User

Simple php for loop instance, phpfor loop instance

The for loop is used to know the number of times the script needs to run in advance.

Syntax

For (initial value; condition; increment) {code to be executed ;}

Parameters:

• Initial Value:It mainly initializes a variable value for setting a counter (but it can be any code that is executed once at the beginning of the loop ).

• Condition:Restrictions on cyclic execution. If it is TRUE, the loop continues. If it is FALSE, the loop ends.

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

Note: The preceding initial value and incremental parameter can be empty or have multiple expressions (separated by commas ).

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

<? Php for ($ I = 1; $ I <= 5; $ I ++) {echo "The number is". $ I. "<br>" ;}?>

Output:

The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

The simple example of the above php for loop usage is all the content shared by xiaobian. I hope you can give us a reference and support the house of friends.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.