Catch and Throw : catch « Statement « Ruby
- Ruby
- Statement
- catch
Catch and Throw
catch(:finish) do
1000.times do
x = rand(1000)
throw :finish if x == 123
end
puts "Generated 1000 random numbers without generating 123!"
end
Related examples in the same category