A simple instance _php instance used by the PHP for loop

Source: Internet
Author: User

A For loop is used when you know in advance how many times a script needs to run.

Grammar

for (initial value; condition; increment) 
{ 
code to execute; 
} 

Parameters:

• Initial value: primarily initializes a variable value that is used to set a counter (but can be any code that executes once at the beginning of the loop).

• Condition: The restriction condition for circular execution. If TRUE, the loop continues. If FALSE, the loop ends.

• Increment: primarily for incrementing counters (but can be any code that executes at the end of the loop).

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

The following instance defines a loop with an initial value of I=1. The loop continues to run as long as the variable i is less than or equal to 5. Each time the loop is run, the 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 above PHP for the use of a simple example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.