2 ms·
> most languages suffer from this Specifically, I think, any language with closures where the loop variable exists in a scope enclosing all loop iterations wit
by dragonwriter 3y ago
> most languages suffer from this
Specifically, I think, any language with closures where the loop variable exists in a scope enclosing all loop iterations with a value that is updated each iteration rather than a fresh variable in a scope local to each loop iteration has this problem.
In Ruby this wouldn't affect idiomatic looping methods like #each, but would seem likely to affect the less-idiomatic for loop, which is built on #each but has the control variable in the surrounding scope. (Not 100% certain how it desugars though.)
- masklinn 3y ago> In Ruby this wouldn't affect idiomatic looping methods like #each, but would seem likely to affect the less-idiomatic for loop, which is built on #each but has the control variable in the surrounding scope. (Not 100% certain how it desugars though.) I don't know how it desugars, but it is indeed affected when using `for...in`