Phpdowhile statement-PHP source code

Source: Internet
Author: User
Ec (2); do... while statements will always execute code blocks once, then check the conditions and repeat the loop, while the conditions are true. Syntax do & nbsp ;{& nbsp; codetobeexecuted; & nbsp ;}while (condition); for example, the following example defines a loop, starting with i1. Then it will add 1 more and write some output. Then, if the condition is checked, the loop will continue to run as long as I am less than or equal to 5: & l script ec (2); script

The do... while statement will always execute the code block once, then check the conditions and repeat the loop, and the conditions are true.

Syntax
Do
{
Code to be executed;
}
While (condition );

For example
The following example defines a loop starting with I = 1. Then it will add 1 more and write some output. Then, if the condition is check, the loop will continue to run as long as I am less than or equal to 5:


$ I = 1;
Do
{
$ I ++;
Echo "The number is". $ I ."
";
}
While ($ I <= 5 );
?>


/* Example 1 */

$ I = 1;
While ($ I <= 10 ){
Echo $ I ++;/* the printed value wocould be
$ I before the increment
(Post-increment )*/
}

/* Example 2 */

$ I = 1;
While ($ I <= 10 ):
Echo $ I;
$ I ++;
Endwhile;
?>


$ Q1 = 'some query on a set of tables ';
$ Q2 = 'similar query on a another set of tables ';

If ($ r1 = mysql_query ($ q1) & ($ r2 = mysql_query ($ q2 ))){

While ($ row = mysql_fetch_assoc ($ r1) | ($ row = mysql_fetch_assoc ($ r2 ))){

/* Do something with $ row coming from $ r1 and $ r2 */

}
}

?>


While ($ data = mysql_fetch_assoc ($ requeteID )){$ Menu. ='$ Menu. = ($ data ['id'] = $ _ GET ['id']? 'Selected> ':'> ');$ Menu. = $ data ['name'].'';}Echo $ menu;?>

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.