The for Statementfor (expr1; expr2; expr3) statement The for loop is the most involved loop in PHP. In this statement, the first expression, expr1, is evaluated once at the beginning of the loop. The continuation expression, expr2, is evaluated at the beginning of each iteration. If it evaluates to TRUE, the loop iterates again, and the nested statement(s) are executed. If it evaluates to FALSE, the loop ends. At the end of each iteration, expr3 is executed, which usually increments a loop counter variable that will be tested in expr2. Here's an example, where the for loop will display text twenty times: <?php for ($loop_counter = 0; $loop_counter < 20; $loop_counter++){ echo "This will print twenty times.<BR>"; } ?> In fact, you can reduce this loop to the following script, where the for loop has no body at all: <?php for ($loop_counter = 0; $loop_counter < 20; echo "This will print twenty times.<BR>", $loop_counter++); ?> |