Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: use of 'continue' block for while/until

by Mutant (Priest)
on Jun 11, 2008 at 08:19 UTC ( #691405=note: print w/ replies, xml ) Need Help??

in reply to use of 'continue' block for while/until

The docs are fairly self explanatory. The main use is if you have a 'next' statement in your main loop block, but you want something to happen after the 'next'. It just gives you an extra level of flow control in loops (see the docs for where each flow control statement will take you).

Trivial example (but hopefully showing basic use):

while ( my $foo = get_next_foo() ) { if ( $foo == 1 ) { next; } do_some_stuff(); } continue { # Everything ends up here whether 'next' was hit or not do_some_more_stuff(); }
You can probably achieve the same thing with if statements, so (in this case at least) it's just syntactic suger.

Comment on Re: use of 'continue' block for while/until
Download Code
Replies are listed 'Best First'.
Re^2: use of 'continue' block for while/until
by GrandFather (Sage) on Jun 11, 2008 at 10:25 UTC

    But sugar of a very sweet kind - it generally saves a level of indentation and avoids obfusification of logic flow.

    Perl is environmentally friendly - it saves trees

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://691405]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-11-27 17:41 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (731 votes), past polls