Ec (2); the number of times specified in the Code block executed by phploopcontinue, or the specified condition is true. -------------------------------------------------------------------------------- The number of times the script should be run when you know in advance. Syntax for (init; condition; increment) script ec (2); script
The number of times specified in the Code block executed by php loop continue, or the specified condition is true.
--------------------------------------------------------------------------------
For Loops
The loop is used when you know how many times the script should be run.
Syntax
For (Init; condition; increment)
{
Code to be executed;
}
Parameters:
Initialization: it is mainly used to set a counter (but it can be any code execution at the beginning of a loop)
Condition: evaluate each loop iteration. If the value is TRUE, the loop continues. If the value is FALSE, the loop ends.
Increment: it is mainly used to add a counter (but it can be that any code will be executed at the end of the loop)
Note: The preceding values can be null, or multiple expressions are used to separate each parameter (separated by commas ).
For example
The following example defines a loop starting with I = 1. The loop will continue to run because I only need to be less than or equal to 5. I will add 1 to run each loop:
For ($ I = 1; $ I <= 5; $ I ++)
{
Echo "The number is". $ I ."
";
}
?>
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
Instance 2
While (list ($ key, $ value) = each ($ arr )){
If (! ($ Key % 2) {// skip odd members
Continue;
}
Do_something_odd ($ value );
}
$ I = 0;
While ($ I ++ <5 ){
Echo "Outer
N ";
While (1 ){
Echo "Middle
N ";
While (1 ){
Echo "Inner
N ";
Continue 3;
}
Echo "This never gets output.
N ";
}
Echo "Neither does this.
N ";
}
?>
For ($ I = 0; $ I <5; ++ $ I ){
If ($ I = 2)
Continue
Print "$ in ";
}
?>