Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Difference between for and foreach

by gube (Parson)
on Sep 17, 2007 at 15:08 UTC ( #639422=note: print w/ replies, xml ) Need Help??


in reply to Difference between for and foreach

Using for you can initialize variable, condition check and increment the varaibles like 'C' or like some other languages. foreach is a function having in perl using you can get the array variable and you cannot initialize or condition check or increment like 'for' in a single line.

Gubs


Comment on Re: Difference between for and foreach
Select or Download Code
Re^2: Difference between for and foreach
by tirwhan (Abbot) on Sep 17, 2007 at 15:31 UTC

    Wrong. See the replies by Joost and johngg, and for practical demonstration try this one-liner

    perl -e 'foreach ($i=0;$i<10;$i++) { print $i }'

    All dogma is stupid.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-08-02 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (54 votes), past polls