From: Tim Hunter Date: 2003-02-01T09:08:00+09:00 Subject: Re: break out of a loop On Fri, 31 Jan 2003 15:26:39 +0900, Vivek Nallur wrote: > > Is there an idiomatic(or more elegant way) of finding out whether I exited > a loop normally or because of an exceptional condition? > > e.g > > 10.times{ > # some processing > > #if (some condition) > break > end > > #further processing > } > > # here i want to know if I came out because of the break or after looping > 10 times. > > Of course, one could set a flag to do the same, but I was wondering if > there was a 'better' way > > regs > Vivek i = 0 catch(:oops) do 10.times { |i| throw :oops if (some condition) } end puts "Loop terminated prematurely" if i < 9 exit