in reply to use of 'continue' block for while/until
my $counter = 0; while ($counter < $limit) { my $item = shift @work_queue; my $thingy = some_function($item); if ($thingy ne 'PARTY') { ++$counter; next; } # more code if $thingy ne 'PARTY' ++$counter; # thanks ikegami }
Here is the same code with the continue block
my $counter = 0; while ($counter < $limit) { my $item = shift @work_queue; my $thingy = some_function($item); next if $thingy ne 'PARTY'; # more code if $thingy ne 'PARTY' } continue { ++$counter; }
Here is my general rule of thumb for when to use continue
It is a nice way of code re-use. Instead of doing
You can just doif ($condition1) { # statement 1 # statement 2 # statement 3 next; } # more code if ($condition2) { # statement 1 # statement 2 # statement 3 next; }
next if $condition1; # more code next if $condition2;
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use of 'continue' block for while/until
by ikegami (Patriarch) on Jun 11, 2008 at 14:01 UTC | |
by Limbic~Region (Chancellor) on Jun 11, 2008 at 15:28 UTC |