Can please someone give an example of third for loop
from specification and explain what does it mean?
14.7.4 The for Statement
Syntax
ForStatement[Yield, Await, Return] :
for ( [lookahead ≠ let [] Expression[~In, ?Yield, ?Await] opt ; Expression[+In, ?Yield, ?Await] opt ; Expression[+In, ?Yield, ?Await] opt ) Statement[?Yield, ?Await, ?Return]
for ( var VariableDeclarationList[~In, ?Yield, ?Await] ; Expression[+In, ?Yield, ?Await] opt ; Expression[+In, ?Yield, ?Await] opt ) Statement[?Yield, ?Await, ?Return]
for ( LexicalDeclaration[~In, ?Yield, ?Await] Expression[+In, ?Yield, ?Await] opt ; Expression[+In, ?Yield, ?Await] opt ) Statement[?Yield, ?Await, ?Return]
2
Answers
It should be something like this:
let i = 0;
is the Lexical Declarationi < 5
is the condition checked before each iterationi++
is executed after each loop iterationIf you look at the definition of
LexicalDeclaration
, you can see it is defined as:So all three cases of
for
loops have two semicolons. Lexical declarations are not expressions and so they have chosen to include the semicolon in its definition, rather than following every use of LexicalDeclaration with ;.