How create infinite loop in javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

How create infinite loop in javascript?

with out crash in browser

25th Sep 2017, 6:13 AM
Mahdi Momeni
Mahdi Momeni - avatar
9 Answers
+ 9
it cause stop working in my browser
25th Sep 2017, 6:31 AM
Mahdi Momeni
Mahdi Momeni - avatar
+ 3
Time limit exceeded only means that the loop takes too much time, not that it is infinite. Here is the proof of what I said : https://code.sololearn.com/c8wNnNcSS7iw/?ref=app PS : you forgot a semicolon
25th Sep 2017, 7:02 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
for (;;) or while (true)
25th Sep 2017, 6:16 AM
Jordan Chapman
Jordan Chapman - avatar
+ 2
@Aleksey, your solution is not infinite (@$Vengat, I think yours too, but I am not sure with JS) x will reach INT_MAX, and INT_MAX + 1 == INT_MIN (due to binary representation of int) As INT_MIN < 0, your loop will break
25th Sep 2017, 6:35 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
setInterval()
25th Sep 2017, 11:19 PM
Ali Sawari
Ali Sawari - avatar
+ 1
while(x>0){ //There what you want x=x+1; } Thats on c++, I think you can do it on js
25th Sep 2017, 6:19 AM
Aleksey Beliy
Aleksey Beliy - avatar
+ 1
for (var i=0;i>-1;i++) Basically a consistently true case
25th Sep 2017, 6:26 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Use setinterval() if performance is not a requirement. https://www.w3schools.com/jsref/met_win_setinterval.asp
25th Sep 2017, 10:01 AM
Khun Ling Tan
Khun Ling Tan - avatar
0
@Baptiste, sry but it's infinite https://code.sololearn.com/c7UYvxqKuNO8/?ref=app
25th Sep 2017, 6:42 AM
Aleksey Beliy
Aleksey Beliy - avatar