Then for loops would be linear in space.
This applies to each-style loops. Actual Ruby for loops don't have this behaviour.
a = []
for i in 1..100
a << ->{ puts i } # append, to a, a function that prints 'i'
end
a[0].call()
This prints 100, since the scope of i covers the entire loop, and not each iteration. They are, however, much faster than each-style loops, since they don't have to make a stack frame for each iteration.[1]: https://blogs.msdn.microsoft.com/oldnewthing/20100809-00/?p=...