Phpwhile syntax and example-PHP source code

Source: Internet
Author: User
Ec (2); while statement Execution code block, if only calculated as true in the specified condition. If the condition becomes false, the statement in the loop stops execution and controls the loop passed to the statement. The syntax of the while loop is as follows: while (condition) {& nbsp; codetobeexecuted;} in the relevant statement, but it is always closed (braces for the opening and closing ceremonies) the code block symbol tells PHP code to know which lines should pass through the loop. While script ec (2); script

The code block executed by the while statement, if calculated as true in the specified condition. If the condition becomes false

To stop execution and control the loop passed to the statement. The syntax of the while loop is as follows:
While (condition)
{
Code to be executed;
}
The code block symbol in the relevant declaration, but always tells PHP code in closed (Opening and Closing braces)

Clear which rows should pass through the loop.

A while LOOP is the most commonly used list with no known criteria and the number of iterations. For example:

While (there are still rows to read from a database)
{
Read in a row;
Move to the next row;
}
Let's take an example. The first example defines a loop starting with I = 0. The loop continues to run as long

Variable I is less than or equal to 10. I will add 1 to run each loop:

$ I = 0;
While ($ I <= 10) {// Output values from 0 to 10
Echo "The number is". $ I ."
";
$ I ++;
}
?>
Now, let's consider a more useful example: create a list of days, months, or years in the drop-down list. You can

Code for using this registration form, for example.

$ Month_array = array ("January", "February", "March", "0000l", "May ",

"June ",
"July", "August", "September", "October", "November ",

"December ");

Echo"";$ I = 1;While ($ I <= 31 ){Echo"". $ I ."";$ I ++;}Echo"";

Echo"";$ I = 0;While ($ I <= 11 ){Echo"". $ Month_array [$ I]."";$ I ++;}Echo"";

Echo"";USD I = 1900;While ($ I <= 2007 ){Echo"". $ I ."";$ I ++;}Echo"";

?>

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.