Application of the For loop in PHP 1

Source: Internet
Author: User

Tag: It increments the learning Loop statement increment for loop structure code

The For loop is the most complex loop structure in PHP. Its behavior is similar to the C language. The number of times to execute the same set of code is used in PHP.

The syntax for the For loop is:

for (EXPR1; expr2; expr3)
Statement

Before I saw the learning video of Qian Feng Education, I have seen such a way of writing:

for ($i =0; $i <=2; $i + +) {
echo $i .& #039;</br> ';
}
$i =0 is the initial value, $i &lt;=2 is the judging condition, $i + + makes the initial value self-increment

In the first loop, $i = 0, which means expression, ($i &lt;= 2), for ture. Therefore, when the print statement executes, the $i gets added 1, which becomes 1.

In the second loop, $ = 1, which means expression, ($i &lt;= 2), for ture. Therefore, when the print statement executes, the $i gets added 1, which becomes 2.

In the third iteration, $i = 2, which means expression, ($i &lt;= 2), for ture. Therefore, when the print statement executes, the $i increments, which becomes 1 3.

In the fourth iteration, $i = 3, which means expression, ($i &lt;= 2), is false. Therefore, PHP does not execute loops and does not execute print statements.

Application of the For loop in PHP 1

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.