break javascript execution from inside timed loop -


how break timed loop inside for? tried 'return', 'break', 'throw'. nothing seems work. continues loop. if try label error:

uncaught syntaxerror: undefined label 'breakout'

var r=0; breakout: for(i=0;i<5;i++) {   settimeout(function() {     if(r) {        alert("works");     } else {        throw new error(alert("error"));        break breakout;     }   }, 2000); } 

http://jsfiddle.net/hyc8j/1/

this function has delay of it's execution... after 2 seconds, loop has far way executed 5 iterations. should put loop inside callback function.

and ask, what's intention this?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -