I have a for loop like so:
for(int i=0; i < 10; i++) {
MyFunc(i);
}
How would I have the program run every 3 seconds so the program would run MyFunc(0) ..wait 3 sec.. MyFunc(1) ..wait 3 sec.. etc?
I have a for loop like so:
for(int i=0; i < 10; i++) {
MyFunc(i);
}
How would I have the program run every 3 seconds so the program would run MyFunc(0) ..wait 3 sec.. MyFunc(1) ..wait 3 sec.. etc?
You need to set a different delay for each iteration:
for(var i=0; i < 10; i++) {
runIt(i);
}
function runIt(i) {
setTimeout(function(){
MyFunc(i);
}, i * 3000);
}
See it in action here:
for(var i=0; i < 10; i++) {
runIt(i);
}
function runIt(i) {
setTimeout(function(){
//MyFunc(i);
document.body.innerHTML = i;
}, i * 3000);
}