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

Re: Difference between for and foreach

by andreas1234567 (Vicar)
on Sep 17, 2007 at 18:31 UTC ( #639459=note: print w/replies, xml ) Need Help??


in reply to Difference between for and foreach

Time to revisit for vs foreach from the year 2000.

perlsyn says:

The foreach keyword is actually a synonym for the for keyword, so you can use foreach for readability or for for brevity.
Update: I now see the link to for vs foreach was already mentioned by n8g above.
--
Andreas

Replies are listed 'Best First'.
Re^2: Difference between for and foreach
by skaurus (Novice) on Jun 13, 2013 at 18:40 UTC
    What about this bit then?

    And it's faster because Perl executes a foreach statement more rapidly than it would the equivalent for loop.

      That comment is about the C-style for loops ( e.g. for ( $i = 0; $i < $j; $i++) versus iterating directly over a list ( e.g. for my $item (@array) ).
        Thanks! I expected a notification email, didn't received one and because of this I saw your answer just now.
      Regarding the context, I would say "the equivalen for loop" means the C-style loop. The documentation should probably be improved there.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://639459]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2017-11-23 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (327 votes). Check out past polls.

    Notices?