Change for statement _php tutorial

Source: Internet
Author: User
In the process of developing the software, there are some times that need to flexibly apply the various forms of the For statement, now the other forms of the For statement, in the form of example code to list out!
The first change, extract the first part of the For-loop syntax
$i = 1;
for (; $i <2; $i + +) {//The first semicolon cannot be omitted
echo "This is the first". $i. " Secondary output!
";
}
?>

The second change, the first part of the For loop syntax is extracted, and the third part of the increment is placed in the For loop body

$i = 1;
for (; $i <2;) {//The first semicolon cannot be omitted
echo "This is the first". $i. " Secondary output!
";
$i + +;
}
?>

The third change, omitting all of the for-loop syntax
$i = 1;
for (;;) {//The first semicolon cannot be omitted
if ($i >1)
Break
echo "This is the first". $i. " Secondary output!
";
$i + +;
}
?>
All programs in Apache 2.2+php5.2.6 Pass!

Poor then change, the general rule Tatsu, it appears in the program also has such a philosophy!



Excerpt from CHUOYUE05 's column

http://www.bkjia.com/PHPjc/478247.html www.bkjia.com true http://www.bkjia.com/PHPjc/478247.html techarticle in the process of developing the software, there are times when it is necessary to flexibly apply the various forms of the For statement, and now the other forms of the For statement are listed in the way of example code!//First change, put for loop syntax ...

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