For loop
for <init>, <end> <body>
init is an initializer, explained below
end is an expression, the value which initial variable iterates through to
The initializer
It could be:
A variable declaration
for var i = 0 ...
for let j = 0 ...
Use
A assign expression
If the target vairable in the assignment is not defined, it will be defined by the let keyword implicitly.
Counting numbers
Printing even numbers
But no parenthese, comma instead of semicolon.
for <init>, <cond>, <updater> <body>
init is loop initializer, it could be an expression
cond is loop condition, an expression
updater is an expression, which is executed after the loop body
Without updater
If the last comma is removed, the loop becomes Simple loop.
Iterating through an array, map.
for <first> [, <second>] : <expr> <body>
first - the first variable
second - the second variable (optional)
expr - an expression to be evaluated, value must be a map or an array
With an array:
Just use for v : arr to get the value only.
With a map:
Depend on the implementation, the key - value pairs may not in input order.
So the output of above example could be:
... or
Like array, just get the key only:
With initializer