The continue block executes when you call next from the middle of the loop, so it provides a way to execute some common code between iterations, regardless of the execution path through each iteration.
Comparison
my $last_item; for my $item (@list) { if ($last_item eq $item) { do_something(); $last_item = $item; next; } if (condition2($item,$last_item)) { $last_item = $item; next; } do_something_else(); $last_item = $item; }
with
my $last_item; for my $item (@list) { if ($last_item eq $item) { do_something(); next; } if (condition2($item,$last_item)) { next; } do_something_else(); } continue { $last_item = $item; }
Some examples of continue in the wild:
HTTP::Cookies
PPIx::Regexp::Node
PDL::Core
source share