Usage of while ()

Source: Internet
Author: User
I saw a code in the php Tutorial: while ($ rowmysql_fetcharray ($ result) {echo $ row [& #039; FirstName & #039;]. & quot ;. $ row [& #039; LastName & #039;]; echo & quot; & amp; lt; br & amp; gt; & quot ;}excuse me & quot; while () & quot; in addition to the function of executing a loop when the value in parentheses is true, what is the purpose... I saw a code in the php Tutorial:

While ($ row = mysql_fetcharray ($ result ))
{Echo $ row ['firstname']. "". $ row ['lastname'];
Echo"
";
}

What is the purpose of "while ()" In addition to the function of executing a loop when the value in the brackets is true? For example, the variables in the preceding Code brackets are neither TRUE nor FALSE.
(For Beginners, you may be an idiot. Please be patient. Thank you)

Reply content:

I saw a code in the php Tutorial:

While ($ row = mysql_fetcharray ($ result ))
{Echo $ row ['firstname']. "". $ row ['lastname'];
Echo"
";
}

What is the purpose of "while ()" In addition to the function of executing a loop when the value in the brackets is true? For example, the variables in the preceding Code brackets are neither TRUE nor FALSE.
(For Beginners, you may be an idiot. Please be patient. Thank you)

Here is not strictly determined, that is, 0, null, array (), false are considered to be false, the same 1, true, 'A', array ('A ') true.

While is a true loop, false is not a loop
However, all values other than 0 are true and 0 is false.
(A = B) returns the value of a, that is, the value of B, after the value is assigned.
Therefore, it can be regarded as true or false.

The prerequisite for determining whether the while clause ends iswhile($row=mysql_fetcharray($result))Internal$row=mysql_fetcharray($result)If it is true, it is always executed. If it is false, the loop is exited.
Another case is that if the while structure contains exit or break, it exits directly.

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.