Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: for loop syntax difference

by Taulmarill (Deacon)
on Aug 28, 2009 at 14:05 UTC ( #791914=note: print w/replies, xml ) Need Help??


in reply to Re: for loop syntax difference
in thread for loop syntax difference

I believe the "for" in the docs refers to a C-style loop (for($i=0;$i<10;$i++)) and the "foreach" refers to the more Perlish style (for $i (1..10)).

Yes, however for and foreach are interchangeable since perl automatically detects which one to use.

Replies are listed 'Best First'.
Re^3: for loop syntax difference
by toolic (Bishop) on Aug 28, 2009 at 14:09 UTC
    Also from the official Perl documentation (For Loops):
    The foreach keyword is actually a synonym for the for keyword, so you can use foreach for readability or for for brevity.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://791914]
help
Chatterbox?
[Corion]: marto: A rough week comes to an end?
Corion has to finish off some test tickets and hopefully close them. Also I have to prepare some information for the tax people on the weekend :-/
[marto]: it feels like 2 weeks :)
[Discipulus]: sane dots for your weekend marto!
[choroba]: My week was hectic as well, and so will be the next several ones...
[Corion]: Sane Dots Supplies - your brand manufacturer for satisfying experiences!
[choroba]: preparing the trip to Vietnam + buying a new car = enough fun

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2017-01-20 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (174 votes). Check out past polls.