I personally think throw/catch is a superior solution because of readability
and the fact that refactoring any loops won't break the code.

-----Original Message-----
From: Wayne Vucenic [mailto:wvucenic / netgate.net]
Sent: Sunday, October 21, 2001 1:01 PM
To: ruby-talk ML
Subject: [ruby-talk:22893] Possible RCR? - break <n> for nested loops


A month or two ago on this mailing list there was a discussion of the
best way to break out of nested loops.  I think a minor change to Ruby
would allow an elegant way to do this.  We could change "break" to
optionally allow an integer argument n, so "break <n>" would break out
of n enclosing loops.  (The Korn shell does this.)

for i in 0..5
    for j in 5..8
        if i == j
            break 2
        end
    end
end

if i == j
    print "match\n"
else
    print "nomatch\n"
end

It seems to me this is a clear, concise solution, that directly
expresses the programmer's intent, which in this case is to "break out
of 2 loops".

If we did this, for consistency we'd probably want to make the same
change to redo, next, and retry.

Wayne