PHP4 User manual: Process Control-for_php Tutorials

Source: Internet
Author: User
For
The For loop is a very complex loop in PHP. It behaves as if it were in the C language. The following is the syntax for looping:
for (EXPR1; expr2; expr3) statement
The first expression (EXPR1) is the value of the loop's unconditional start.
At each iteration, the expression expr2 is computed. If the value is true, the loop continues, executing the nested statement. If the value is false, the execution of the loop after the
At each iteration, the expression EXPR3 is computed (executed).
Each expression can be empty. EXPR2 null means that the loop will run indeterminate (PHP implicitly thinks it is true, like C). It's not going to end like you think, you can use the Web site Building server script Class \phpphp user manual Fancycontrol-structures.break.html>break statement to replace the for fact expression to end the loop.
Consider the following example. They will show numbers from 1 to 10:
/* Example 1 */for ($i = 1; $i <=; $i + +) {print $i;} /* Example 2 */for ($i = 1;; $i + +) {if ($i >) {break;} print $i;} /* Example 3 */$i = 1;for (;;) {if ($i >) {break;} print $i; $i + +;} /* Example 4 */for ($i = 1; $i <=; print $i, $i + +);
Of course, from the first example, it is abbreviated (or fourth), but you can see that there are a lot of opportunities for you to use an empty expression.
PHP still supports the "colon syntax" of loops.
for (EXPR1; expr2; expr3): statement; ...; ENDfor;
Another my language has a foreach statement to manipulate arrays or hashes. There is no such construct in PHP 3; PHP 4 is (see foreach). In PHP 3, people can use the while, List (), and each () functions to do the same thing. See the documentation for these functions.

http://www.bkjia.com/PHPjc/532350.html www.bkjia.com true http://www.bkjia.com/PHPjc/532350.html techarticle The for-for loop is a very complex loop in PHP. It behaves as if it were in the C language. The following is the syntax of the loop: for (EXPR1; expr2; expr3) statement the first expression (EXPR1) is a loop ...

  • Related Article

    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.