Example of php for loop usage, php instance

Source: Internet
Author: User
Tags strtok

Example of php for loop usage, php 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: Initializes a variable value to set 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.
  • Incremental: It is mainly used for incremental counters (but can be any code executed at the end of the loop ).

Note:The aboveInitial ValueAndIncrementalThe parameter can be null or multiple expressions (separated by commas ).

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

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

Output:

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

 

Address: http://www.manongjc.com/php/php_while.html

Related reading:

Php strtok () usage-php strtok () function example

Difference between strtok () and explode () in php string segmentation Function

Php strtr () string replacement function Usage Analysis

Php substr () intercepts the specified length of the substring from the specified position of the string

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.