PHP for loop Use simple instance, Phpfor Loop instance _php Tutorial

Source: Internet
Author: User

A simple instance of PHP for loop use, Phpfor loop instance


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

Grammar

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

• Conditions: cyclic execution of restrictions. If true, the loop continues. If FALSE, the loop ends.

• Increment: used primarily 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:

<?php for ($i =1; $i <=5; $i + +) {echo "the number is". $i. "

Output:

The above this PHP for loop use of a simple example is the small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we have a lot of support to help guests home.

http://www.bkjia.com/PHPjc/1133025.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133025.html techarticle a simple instance of the PHP for loop uses a phpfor loop instance for loop that you know beforehand how many times the script needs to run. Syntax for (initial value; condition; increment) {The generation to be executed ...

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