Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How does next label work?

by LanX (Saint)
on Jan 06, 2013 at 09:49 UTC ( [id://1011865]=note: print w/replies, xml ) Need Help??


in reply to How does next label work?

Naked blocks are documented as being internally implemented as loops which are only executed once.¹

next is a loop control which reevaluates the condition, which is false now.

It's no goto, you can only use if for lables just in front of loop-starts, OTOH gotos can jump to any lables in the same scope.

For your purpose better try redo

> perl { print $x++; redo if $x<6; } __END__ 012345
or real gotos

> perl X: { print $x++; goto X if $x<6; } __END__ 012345

Cheers Rolf

UPDATES:

¹)from perlsyn

Basic BLOCKs A BLOCK by itself (labeled or not) is semantically equivalent t +o a loop that executes once. Thus you can use any of the loop control statements in it to leave or restart the block.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found