Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

RE: Re: for vs foreach

by perlmonkey (Hermit)
on Jul 14, 2000 at 20:39 UTC ( [id://22585]=note: print w/replies, xml ) Need Help??


in reply to Re: for vs foreach
in thread for vs foreach

See the comments above, your statement is incorrect. for can just as easily iterate over a list as foreach (without an explicit iterator), they are completly interchangeable.
@a = ( 1, 2, 3, 4); for(@a) { print; } print "\n"; foreach(@a) { print; } print "\n"; for($i=0; $i<@a; $i++) { print @a[$i]; } print "\n"; foreach($i=0; $i<@a; $i++) { print @a[$i]; } print "\n";
Results:
1234 1234 1234 1234

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-25 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found