how to break a timed loop inside a for? I tried 'return', 'break', 'throw'. Nothing seems to work. It just continues with the loop. If I try with a label I get an 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);
}