skip to Main Content

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


  1. It should be something like this:

    for (let i = 0; i < 5; i++) {
        console.log(i);
    }
    
    • let i = 0; is the Lexical Declaration
    • i < 5 is the condition checked before each iteration
    • i++ is executed after each loop iteration
    Login or Signup to reply.
  2. If you look at the definition of LexicalDeclaration, you can see it is defined as:

    • LexicalDeclaration[In, Yield, Await] :
      • LetOrConst BindingList[?In, ?Yield, ?Await] ;

    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 ;.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search