Looping in Ruby
Looping in Ruby
An important and powerful concept to understand in any programming language is looping. By using loops we can iterate through arrays and interact with each piece of data in the array until a certain condition is met. If you know how t...
kadeesterline.hashnode.dev5 min read
Nice writeup.
I noticed that
catchandthrowwas missing.def using_throw arr arr.each do |i| throw :early if i > 5 puts arr[i] end end catch :early do using_throw [1, 2, 3, 4, 5, 6, 7, 8] endDemonstrates that the catch does not need to be in the same method.
def using_throw arr catch :early do arr.each do |i| throw :early if i > 5 puts arr[i] end end end using_throw [1, 2, 3, 4, 5, 6, 7, 8]If we want to catch in the method itself.