Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: how do foreach and while affect an array?

by jbware (Chaplain)
on Sep 12, 2004 at 16:57 UTC ( [id://390444]=note: print w/replies, xml ) Need Help??


in reply to how do foreach and while affect an array?

foreach is nondestructive.

Update I just reread that question. Both foreach and while are nondestructive. You can iterate through arrays using foreach and while w/o worrying about losing data.

-jbWare

Replies are listed 'Best First'.
Re^2: how do foreach and while affect an array?
by zdog (Priest) on Sep 12, 2004 at 20:27 UTC
    You can iterate through arrays using foreach and while w/o worrying about losing data.

    Yes, foreach() ( aka for() ) does iterate through the array, and it does not affect the contents of the array on its own. But just to be clear, one doesn't iterate through arrays with while().

    while() can indeed be utilized to run through an array, but whether that affects the contents of the array depends on the implementation. In the end, while() does not operate on arrays on its own in any fashion.

    Zenon Zabinski | zdog | zdog@perlmonk.org

Log In?
Username:
Password:

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

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

    No recent polls found