On Sun, 2001-10-21 at 20:00, Wayne Vucenic wrote:
> 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.)

On first look, my thought is "ick"... and here's why... I often find
myself adding or removing nested loops as code evolves.  Hard-coding the
number of loops to break out of would introduce extra interdependencies
in the code.   Code using this would break, sometimes non-obviously,
whenever a loop was promoted or demoted a level.

Anyway, Ruby already has 'catch/throw' (not to be confused with 'raise')
which seems to me to address this problem quite well... but perhaps I'm
missing something.

Some languages, (perl comes to mind), have optional labels in front of
loops, allowing 'break' to break up to the level of a given label. This
is a nice clean solution.  I'm not sure it has any advantage over
'catch/throw' however, unless it's in conciseness.

my $0.02...

~Avdi