Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

settimeout inside for loop

var counter = 0;

// A single iteration of your loop
// log the current value of counter as an example
// then wait before doing the next iteration
function printCounter() {
    console.log(counter);
    counter++;
    if (counter < 10)
        setTimeout(printCounter, 1000);
}

// Start the loop    
printCounter();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #settimeout #loop
ADD COMMENT
Topic
Name
7+6 =