Consider this python code
it = iter([1, 2, 3, 4, 5])
for x in it:
print x
if x == 3:
break
print '---'
for x in it:
print x
it prints 1 2 3 --- 4 5because the iterator itremembers its state looped. When I do, it seems the same thing in JS, all I get is this 1 2 3 ---.
function* iter(a) {
yield* a;
}
it = iter([1, 2, 3, 4, 5])
for (let x of it) {
console.log(x)
if (x === 3)
break
}
console.log('---')
for (let x of it) {
console.log(x)
}
Run codeHide resultWhat am I missing?
georg source
share