Having problem with delay | SoloLearn: Learn to code for FREE!

0

Having problem with delay

Hi everyone, how can i make a delay for each iteration in “for loop”? I tried: for (i = 0; i < 101; i++) { setTimeout(function() { document.getElementById("test").value = i },1000) } But still not work. Can anyone help me?

4/30/2020 5:59:11 PM

Allan Nguyễn

3 Answers

New Answer

+2

Fixed... (I guess ;P) https://code.sololearn.com/Wm9704l3T3lA/?ref=app

0

Allan Nguyễn wait a few: there's a problem... I repost the code as soon as fixed ;)

0

Little update on previous code (support of null or not functions callbacks wasn't completly done ^^). ... and a second version (shortened name: TimeoutLoop => TimedLoop) nestable and breakable (stop() method, 'continue' should be simply done by returning from 'iter' callback argument). https://code.sololearn.com/W1KM46A0oqiV/?ref=app It's the 3rd or 4th time I implement such generic "async" nestable loop... the simple version was quick to implement, the nestable one still is not completly obvious, even if each time I redo the job from scratch I take lesser time ^^ (I'm too lazy to write an how to use, but if someone would need, just ask in comment of the code: I could at least guide if not enough motivated to write a complete documentation -- however, I guess that exploring the 30 lines of code would be enough to understand how to use it ;))