PHP for Loop Use example Introduction, PHP instance _php tutorial

Source: Internet
Author: User

PHP for Loop Use example Introduction, PHP instance


The For loop is used in cases where you know in advance how many times the script needs to run.

Grammar

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

Parameters:

    • Initial value : The primary is to initialize a variable value that sets a counter (but can be any code that is executed once at the beginning of the loop).
    • condition : The throttling condition of the loop execution. If true, the loop continues. If FALSE, the loop ends.
    • increment : Mainly used for incrementing the counter (but can be any code executed at the end of the loop).

Note: The above initial and increment parameters can be empty, or there are multiple expressions (separated by commas).

The following example 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. Each time the loop is run, the variable i increments by 1:

 
  ";}? >

Output:

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

Original address: http://www.manongjc.com/php/php_while.html

Related reading:

PHP strtok () Usage-php strtok () Function Example explained

The difference between PHP string segmentation function Strtok () and explode ()

PHP strtr () string substitution function usage Analysis

PHP substr () intercepts substrings of a specified length from the specified position in the string

http://www.bkjia.com/PHPjc/1130979.html www.bkjia.com true http://www.bkjia.com/PHPjc/1130979.html techarticle the PHP for loop uses an example, and the PHP instance for loop is used in cases where you know in advance how many times the script needs to run. Syntax for (initial value; condition; increment) {code to execute;} parameter ...

  • 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.