This is an example:
function func1()
{
setTimeout(function(){doSomething();}, 3000);
}
for(i=0;i<10;i++)
{
func1();
}
after executing it , the delay happens only in the first loop, but it didn't happen in the rest of the loops in that 'for' expression.
I want to make the delay happen in all of the loop and not only in the first time.
What's wrong in my code ?
doSomethings are scheduled to execute 3 seconds from when they are scheduled. Since they are scheduled right after one another with barely any time between them, they will execute 3 seconds after that, with barely any time between them. What did you expect to happen? If you wanted them to execute with 3 seconds between each of them, schedule them at 3000, 6000, 9000... or schedule the next one at the end of the current one, not in a loop outside of them.setTimeout. But all of thesetTimeoutcalls are executed in a loop, without delay between them.