Dynamic change of "each" loops in Ruby
loops, ruby
Solution
Why not just `break`?
(startIndex..endIndex).each do |value|
p value
break if value>=150
end
'cause it's really bad practice to dynamically change loop limits.
Problem
I am a newie in Ruby and I am facing a problem regarding "each"-like loops. Suppose a code like the following ``` startIndex = 1 endIndex = 200 (startIndex..endIndex).each do |value| p value if value>150 then endIndex=100 end ``` When I run the code it will run until 200, not until 150. Is there any way to change the limits of the loop range dynamically in Ruby? Thanks in advance for your help Tryskele