TIL: Ruby's Loop Automatically Breaks at the End of Iteration
Autobreaking loops with iterators
The loop
statement doesn't get a lot of love, but it will automatically catch a StopIteration
error and break nicely.
iter = (1..3).each
loop do
p iter.next
end
# 1
# 2
# 3
Member discussion