PHP4 User Manual: Process Control -> While

zhaozj2021-02-08  215

While

The While loop is a simple type in the PHP loop. Its behavior is just like the C language. The following is a basic WHILE statement:

While (expr) Statement

The meaning of this While statement is very simple. It tells PHP as long as the value of the While expression is true, then repeat STATEMENT (S). At the beginning of each cycle, check the value of the expression, if the value of this expression is changed during execution, the program will end after the excessive duplicate content. Sometimes, if the value of the expression is false from the beginning, Statement (s) will not be executed once.

Like the IF statement, you can make multiple statements in a group of braces. Or by Using the alternate syntax:

While (expr): Statement ... endwhile;

The following two cases are the same, all output 1 to 10:

/ * EXAMPLE 1 * /

$ i = 1;

While ($ I <= 10) {

Print $ i ; / * The Printed Value Would Be

$ I Before The Increment

(Post-increat) * /

}

/ * EXAMPLE 2 * /

$ I = 1;

While ($ I <= 10):

Print $ I;

$ i ;

Endwhile;

转载请注明原文地址:https://www.9cbs.com/read-3404.html

New Post(0)