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
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