I have some javascript code that is being executed before it is supposed to be and I do not know why. Basically, I have a for loop that is supposed to be executed 50,000 times. However, this takes a while so I want to have a progress bar that updates as the for loop is being executed. So, I have an if statement that says if u is at 500, the value of o is set to 0 and the progress bar is updated 1%, and if the progress bar is at 100%, to execute some other code. However, that other code is being executed way before u reaches 100 and I have no idea why.
function thisFunction(){
var o=0;
var u=0;
for(i=1;i<=50000;i++){
if(o===500){
o=0;
u +=1;
$("#myProgressBar .progress .progress-bar").css('width',u+'%');
$("#myProgressBar .progress .progress-bar").html(u+'%');
if(u>99){
$("#myProgressBar").addClass("hidden");
/*Other code*/
}
else{
}
}
else{
}
/*code that needs to be executed 50,000 times*/
o +=1;
}