[javascript] how do I create an infinite loop in JavaScript

I want to create an infinite loop in JavaScript.

What are some ways to achieve this:

eg

for (var i=0; i<Infinity; i++) {}

This question is related to javascript loops infinite-loop

The answer is


You can also use a while loop:

while (true) {
    //your code
}

By omitting all parts of the head, the loop can also become infinite:

for (;;) {}

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to loops

How to increment a letter N times per iteration and store in an array? Angular 2 Cannot find control with unspecified name attribute on formArrays What is the difference between i = i + 1 and i += 1 in a 'for' loop? Prime numbers between 1 to 100 in C Programming Language Python Loop: List Index Out of Range JavaScript: Difference between .forEach() and .map() Why does using from __future__ import print_function breaks Python2-style print? Creating an array from a text file in Bash Iterate through dictionary values? C# Wait until condition is true

Examples related to infinite-loop

how do I create an infinite loop in JavaScript break statement in "if else" - java Endless loop in C/C++ How to run the Python program forever? How to get out of while loop in java with Scanner method "hasNext" as condition? Python - A keyboard command to stop infinite loop? How to create an infinite loop in Windows batch file? Which is the correct C# infinite loop, for (;;) or while (true)?