On Tue, Aug 21, 2001 at 03:40:04PM +0900, John Tromp wrote:
> 
> I wonder what's the proper way to break out of nested loops,
> and how to do some statement if the loops finished normally.
> right now i use the construct
> 
> print "nomatch\n" unless for i in 0...5 do
>   break unless for j in 5...8 do
>     if i==j
>       print "match\n"
>       break
>     end
>   end
> end
> 
> but it feels like cheating:) and is not nearly as readable as i'd like
> it to be. i could of course do it nicely by seperating the loops into
> a function, but was wondering if there's another way...
> 
> regards,
> 
There is no 'proper way' ;) but I do the following, learned from
the Practical Programming book (no tested!)

catch (:done) do 
  for i in (0..5)
    catch (:done2) do 
      for i in (j..i+10)
         throw :done if foo[i][j] == i
         throw :done2 if foo[i][j] < i
      end
    end
    # done2: continue for i ...
  end
end
# done: end of nested loop