Answer the question
In order to leave comments, you need to log in
How to stop the for loop and then continue from the step where you left off?
I need to implement a For loop when a button is clicked, take into account the conditions that the loop should take a step and stop. When you click on the same button, continue the cycle from the step where it stopped.
The if option with a counter is not suitable, I need it with the for loop.
Answer the question
In order to leave comments, you need to log in
Generator (except IE).
function* generator() {
for (let i = 0; i < 2; i += 1) {
yield i;
}
}
const gen = generator();
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // undefined
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question