From: kjana@...4lab.to (YANAGAWA Kazuhisa) Date: 2003-02-01T11:29:55+09:00 Subject: Re: break out of a loop In message cyclists@nc.rr.com writes: > i = 0 > catch(:oops) do > 10.times { |i| > throw :oops if (some condition) > } > end > puts "Loop terminated prematurely" if i < 9 > exit Or more: result = catch(:oops) do 10.times {|i| throw(:oops, :break) if some_condition} end # result == :break if some condition Namely throw can throw some value to a catch tag and catch returns the thrown value. So you also can break out on multiple conditions and know the cause, or break nested loop and distinguish which loop breaks. # with no throw, result is a value of a block given to catch. -- kjana@dm4lab.to February 1, 2003 Of two evils choose the lesser.