The most common one is for (Initial Value of the loop variable; cyclic condition; Incremental Value) {statement ;}
Example
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Other usage
(1) omitted expression 1. In this case, the initial value should be assigned to the loop variable before the for statement. Pay attention to the subsequent values.
Example:
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
(2) omitting expression 2, that is, the loop condition loop is not terminated, that is, expression 2 is always true.
Example:
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
(3) omit expression 3, but ensure that the loop can end normally.
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
(4) omitted expression 1, 3
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
This is equivalent to while. You can use for to replace while.
(5) All three expressions are omitted.
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
In this way, the loop will not be terminated. Similarly, this small while (true) {} function.
(6) expression 1 can be the initial value of the cyclic variable or other expressions irrelevant to the cyclic variable.
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Expressions 1 and 3 can also be comma expressions (including more than one expression, separated by commas );
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The value of the comma expression is the rightmost value in the order from left to right.
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
This is
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
(7) The expression can be a logical expression or a character expression. A loop can be executed if it is not false.
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute] from these, we can see that the for and while loops are very powerful.