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

Re: for, foreach: any difference?

by Limbic~Region (Chancellor)
on Apr 02, 2004 at 17:20 UTC ( [id://342039]=note: print w/replies, xml ) Need Help??


in reply to for, foreach: any difference?

MUBA,
Ok - yes and no - depends on how you look at it. One is usually referred to as a C-style for loop (does not localize $_ or implicitly alias looping variable) and the other is typically referred to as a foreach loop (which does both of those things).
for ( $i = 0; $i < 10; $i++ ) { # C-style but could also say foreach } foreach ( @array ) { # Localizes $_ and implicitly aliases looping variable # Could also just be for }
In your code, it does not matter which name you use. It is the looping construct that follows the name that determines the internal behavior.

Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found