Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Why add a loop keyword to JavaScript?


I think the loop keyword is only going to make people confused when they try to use what they learned here elsewhere.

Why add this confusion when you can avoid it by replacing loop with while(true)?


loop { is meant to prevent new programmers to make an infinite loop. The while(True) loop does something like this:


This can easily result in an infinite loop. On the other hand, the loop { keyword does something like this:


This prevents an infinite loop in most cases.


You could make every method of the game(like this.attack) to call this waitForNextFrame() before it returns. And you could also have something like this.onNewFrame() method.

Another problem is that you are making people used to something that you won’t often find. Languages that do have a loop keyword will behave just like a while(true).

Maybe the benefit of simplify by adding this keyword outweighs the problems. But I feel that this is not the case.


More discussion on this here:

We are considering not including loop in the future, but haven’t made a decision yet.