Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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

Replies are listed 'Best First'.
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?
[stevieb]: in a C++ header file, if a function declaration is listed twice with each listing containing different params, that's just essentially allowing one function accept two different arg lists, yes?
[stevieb]: int func(int x, int y);
[stevieb]: int func(int x);
[stevieb]: For example

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-06-28 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (653 votes). Check out past polls.