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

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.

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.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2018-07-17 02:39 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (353 votes). Check out past polls.