On 2/28/07, Pit Capitain <pit / capitain.de> wrote: > gga schrieb: > > For completeness sake, you can also emulate C's lack of a break; > > statement in ruby by doing redo/retry, like: > > > > a = 1 > > > > catch(:redo) do > > case a > > when 1 > > print '1' > > a = 2 > > redo > > when 2 > > puts 'and 2' > > end > > end > > > > This makes ruby's case statement probably the best of any language. > > I didn't know the "catch(:redo)". Is this documented somewhere? Well the redo is really reacting as part of the catch block (though other block forms would do). Consider this example: def my_iter(exp) yield end my_iterr(p(:arg)) {p :block} #=> :arg and :ok once in order # Caution with the following. have ^C handy my_iter(p(:arg)) {p :before; redo; p :after} #=> :arg once and then infinite loop of :before my_iter(p(:arg)) {p :before; retry; p :after} #=> :arg then :before. both repeated infinitely Brian.