Why does the browser freeze in a loop at i + 1?

  • 0
    There is a loop for (let i = 0; i & lt; = 1; i + 1) {} . When it starts, chrome hangs. When I change to for (let i = 0; i & lt; = 1; i ++) {} , everything is fine. What is the problem?
    JavaScript Isla Larsen, Mar 25, 2020

  • 3 Answers
  • 0
    What's the problem?


    When i + 1 , the value of i does not change and the loop loops forever)
    Anonymous

  • 0
    the problem is that "i + 1" does not change the variable i - an infinite loop is obtained. You should have written "i = i + 1" or "i + = 1"
    Adalaide Archer

  • 0
    i ++ is identical to i = i + 1



    your loop is eternal, as the value of i does not change



    If you really don't want to use i ++ , then use it this way:

    for (let i = 0; i & lt; = 1; i = i + 1) {}
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!