I have this code:
$(function(){
var steps = ["download","unpack","install","installed"];
for(var i = 1; i <= steps.length; i++){
setTimeout(function(){
if(updater(steps[i]) === false) break; // if update fails
else{
var progress = (i / steps.length) * 100;
$("div#update div.progress div.progress-bar").animate({
width : progress+"%"
}).attr("aria-valuenow", progress);
}
, 5000)
}
if(steps.length === i){ // update is fully installed
alertBox("success", "Congratulations, a new version of the SocialTab 3 has been installed.", 31556952000);
}
else{ // update failed
alertBox("error", "<p>Update failed!</p><p>"+updateError+"</p>", 31556952000);
}
});
When I do this, I can't use break because it should be used in a for loop, which it isn't because I put it in a setTimeout function.
I want to know how I can break out of the for loop and still delay the code within the setTimeout function.