| PHP - for Function Control | | Print | |
A for loop is a more complex looping construct than the simple while loop:
for(start_expr; cond_expr; iter_expr) {
statements
}
for(start_expr; cond_expr; iter_expr):
statements
endfor;
A for loop takes three expressions. The first is the start expression; it is evaluated once when the loop begins. This is generally used for initializing a loop counter. The second expression is a conditional expression that controls the iteration of the loop. This expression is checked prior to each iteration. The third expression, the iterative expression, is evaluated at the end of each iteration and is typically used to increment the loop counter. With the first form of the for statement, you can omit the braces if you only need to execute a single statement.
The break and continue statements work with a for loop like they do with a while loop, except that continue causes the iterative expression to be evaluated before the loop conditional expression is checked.
| Users' Comments (0) |
|
No comment posted





