While // while is to first judge the condition, if it is true, it is executed and executed multiple times, knowing that the condition is invalid
While // while is to first judge the condition, if it is true, it is executed and executed multiple times, knowing that the condition is invalid
Syntax:
While (expression)
Execute a statement repeatedly;
While (expression ){
Execute this loop body repeatedly
}
------------------------------------------------------------------------
Do-while // do-while is the condition that is first executed and then judged
------------------------------------------------------------------------
For
Syntax:
For (initial activation; conditional expression; increment ){
Loop body
}
------------------------------------------------------------------------
While example:
$ Num = 0;
While ($ num <100 ){
Echo "this is the result of executing the {$ num} output.
";
$ Num ++;
}
------------------------------------------------------------------------
While Example 2: // 100 rows, 10 columns, rows, color-changing tables
Echo'
This is a 1000 grid table. ';
Echo'
$ A = 0;
While ($ a <1000)
{
If ($ a % 20 = 0) {$ bg = '# fff111';} else {$ bg = '# ffff ';}
If ($ a % 10 = 0) {echo'
Echo'
$ A ++;
If ($ a % 10 = 0) {echo'
}
Echo'
';
?>
------------------------------------------------------------------------
For example: // you can write multiple expressions.
For ($ I = 0, $ j = 100; $ I <10 & $ j> 50; $ I ++, $ j-= 10 ){
Echo "this is the result of executing $ j in the first $ I loop.
";
}
------------------------------------------------------------------------
For loop instance // 99 multiplication table
For ($ I = 1; $ I <= 9; $ I ++ ){
For ($ j = 1; $ j <= $ I; $ j ++ ){
Echo "{$ j} * {$ I} =". $ I * $ j .'';
}
Echo'
';
}
?>
------------------------------------------------------------------------
Several loop-related statements
Break; // skip loop
Continue; // jumps out of this loop and does not affect other loops.
Exit;
Return;
------------------------------------------------------------------------
Example of break and continue
For ($ I = 0; I I <100; $ I ++ ){
If ($ I = 50)
Break;
Echo "$ I ###################
";
}
For ($ I = 0; I I <100; $ I ++ ){
If ($ I % 3 = 0)
Continue;
Echo "$ I ###################
";
}
?>