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); }
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
Post a Comment