From: Patrick Hurley Date: 2006-09-08T21:44:21+09:00 Subject: Re: continuing the next iteration On 9/8/06, Patrick Hurley wrote: > On 9/7/06, YAD wrote: > > What's the Ruby equivalent of "next" in Perl or "continue" in C? > > Is it possible to continue an outer loop, as in Perl's "next" > > with a label argument? > > > > -- > > Yet another Dan > > > > > > Try catch/throw, although if you can rework your code into smaller > chunks and use a return it is often more readable. > > catch (:deep_error) do > (0..10).each do |i| > puts i > (0..10).each do |j| > puts j > throw :deep_error if 2 == j > end > end > end > puts "done" > Sorry I did not read as closely as I should -- my example was just of a "break," if you are after next/continue functionality, you need to put the catch/throw inside the outer loop: (0..10).each do |i| puts i catch :deep_error do (0..10).each do |j| puts j (0..10).each do |k| puts k throw :deep_error if 2 == k end end puts "never going to happen" end end