This section provides a quick description of the 'for' loop statement.
The "for" statement is a very common loop statement in many programming languages.
The JavaScript "for" statement has the following generic syntax format:
for ([initial_exp]; [loop_condition]; [increment_exp])
statement or statement_block
If you want to know exactly how a "for" statement will be executed, here is
my understanding:
Step 1: "intial_exp", usually an assignment expression, is evaluated.
Step 2: "loop_condition", a Boolean expression, is evaluated.
Step 3: If "loop_condition" is evaluated to "true", continue with Step 5.
Step 4: If "loop_condition" is evaluated to "false", terminate the loop.
Step 5: Execute "statement" or "statement_block".
Step 6: "increment_exp", usually an assignment expression, is evaluated.
Step 7: Continue with Step 2.
"for" loop statement could be executed infinitely, if the "loop_condition" is always evaluated to "true".
A "break" statement could be used inside the loop statement block to terminate the loop early.
A "continue" statement could be used inside the loop statement block to skip the rest of the block
and start the next iteration of the loop.
A tutorial example will be given in the next section showing an example of the "for" loop statement.