Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: arrays: shifting in while loop

by repellent (Priest)
on Mar 07, 2012 at 05:01 UTC ( [id://958207]=note: print w/replies, xml ) Need Help??


in reply to Re: arrays: shifting in while loop
in thread arrays: shifting in while loop

    ... loop execution will continue regardless of the state of the array unless an explicit loop exit is made ...

Hmm, really? I always thought the while-loop EXPR was re-evaluated after each iteration:
my @a = (3, 4); while (do { say "yo"; @a }) { say "hi mom"; shift @a; # no explicit loop break out } say "bye mom"; __END__ yo hi mom yo hi mom yo bye mom

Replies are listed 'Best First'.
Re^3: arrays: shifting in while loop
by AnomalousMonk (Archbishop) on Mar 07, 2012 at 15:17 UTC
    ... the while-loop EXPR [is] re-evaluated after each iteration...

    It is, but I was trying to make a (perhaps rather trivial) point with regard to continued execution of the loop body (which I've tried to clarify in the original reply) as exemplified below.

    >perl -wMstrict -le "my @ra = (9, 8, 7); ;; while (@ra) { print 0+@ra, ' in @ra'; shift @ra; print 0+@ra, ' in @ra'; shift @ra; print 0+@ra, ' in @ra'; shift @ra; print 0+@ra, ' in @ra'; shift @ra; print 0+@ra, ' in @ra'; shift @ra; print 0+@ra, ' in @ra'; } " 3 in @ra 2 in @ra 1 in @ra 0 in @ra 0 in @ra 0 in @ra
      Great, I knew I missed something from your original post.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-03-28 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found