Loop structure:
For while Do....while
For loop
for (variable initialization; conditional expression; variable update) {
???? Loop body
}
Description
???? First step: variable initialization is performed only once
???? The second step: to determine whether the expression is set up, the execution of the loop body is not established, then jump out of the loop
???? Step three: Expression set up execution loop body then variable update
???? 2-à3-à 4-à 2-à3-à4 until the expression is not set to exit the loop
???? Interlaced color of tables
99 Multiplication Table:
While
Grammar:
Variable initialization
while (conditional expression) {
???? Loop body
???? Variable update
}
Description
???? The loop body is executed when the conditional expression is formed, and the loop is exited instead
???? To prevent a dead loop we usually define a variable initialization outside of the loop and add a variable update to the loop body.
Do....while
Grammar:
do{
???? Loop body
}while (conditional expression)
Description
???? Execute the loop body and then judge the conditional expression first
???? If the expression is true, the loop body is executed, and the reverse is not performed.
???? To prevent a dead loop we usually define a variable initialization outside of the loop and add a variable update to the loop body.
The difference between a for loop and a while loop
Number of known cycles using for loop, unknown loop count using while
The difference between while and do....while
Do.. While the conditional expression is true, it executes once
While if the conditional expression is not true, it does not execute
JS Loop structure