From: Wayne Conrad Date: 2001-10-22T05:15:10+09:00 Subject: [ruby-talk:22896] Re: Possible RCR? - break for nested loops On Sun, 21 October 2001, Wayne Vucenic wrote: > > ... We could change "break" to > optionally allow an integer argument n, so "break " would break out > of n enclosing loops. ... > > for i in 0..5 > for j in 5..8 > if i == j > break 2 > end > end > end Wayne, Great name! :) For that example, I think throw & catch read clearer, because I don't have to count (I'm a lousy counter). I like this better even though the additional block adds some noise: catch (:done) do for i in 0..5 for j in 5..8 if i == j throw :done end end end end This is very similar to a Java labeled break. More readable would be a Pascal-style goto, but I do not propose adding Pascal-style goto's to Ruby -- I can imagine many difficulties implementing them, and not a whole lot of problems they would solve better than exceptions & catch/throw do. Wayne Conrad