+ 6

Infinite function in JavaScript

How to run a function in JavaScript forever?

13th Feb 2017, 6:22 PM
Samuel Šúr
Samuel Šúr - avatar
5 Réponses
+ 16
setInterval(func,millis);
13th Feb 2017, 7:04 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
Thanks
13th Feb 2017, 7:08 PM
Samuel Šúr
Samuel Šúr - avatar
+ 4
but how to...I' m new to JavaScript
13th Feb 2017, 6:31 PM
Samuel Šúr
Samuel Šúr - avatar
+ 4
This a basic loop : var i=0; while (i<=10) { document.write(i + "<br />"); i++; } The i++ means that the variable i increase, and i increae from 0 to reach 10 in this loop. You can change the value of i, and to make this loop infinite, you can just remove the i++ (increament). So if i=1, the function will write 1 infinite of times on each lines, but this kind of loop can crash your browser if you run the loop on it, or it will just doesn't work to prevent a crash. I hope my answer helpful for you, and have fun with loops :D
13th Feb 2017, 7:18 PM
San_Antonio
San_Antonio - avatar
+ 2
Use an infinite loop (recursive or iterative)
13th Feb 2017, 6:30 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar