Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: for loop syntax difference

by Taulmarill (Deacon)
on Aug 28, 2009 at 14:02 UTC ( #791909=note: print w/ replies, xml ) Need Help??


in reply to for loop syntax difference

for $i (1..10) creates a list with ten elements and iterates of that.
for($i=0;$i<10;$i++) initializes $i with the value 0, then for every iteration of the loop it checks $i and increments if the check returns true or ends the loop.


Comment on Re: for loop syntax difference
Re^2: for loop syntax difference
by ikegami (Pope) on Aug 28, 2009 at 14:05 UTC

    for $i (1..10) creates a list with ten elements and iterates of that.

    No, it doesn't. It's optimised into a counting loop. It increments the loop counter every pass rather than creating a list.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2015-07-06 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls