sir_com has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
going through some site or in some post in perlmonk site, I saw that there is a difference in the for loop syntax. They say that for $i (1..10) is much efficient than for($i=0;$i<10;$i++). For example the below code for $i (1..10) { print "HI\n"; } is efficient than for($i=0;$i<10;$i++) { print "HI\n"; }. I don't understand where does the efficiency part coming here, cause in both the cases the "print" statement going to execute for 10 or n times. Then how does the first "for" syntax is efficient? Can somone please explain?
thanks, sir_com
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: for loop syntax difference
by toolic (Bishop) on Aug 28, 2009 at 14:00 UTC | |
by Taulmarill (Deacon) on Aug 28, 2009 at 14:05 UTC | |
by toolic (Bishop) on Aug 28, 2009 at 14:09 UTC | |
Re: for loop syntax difference
by bv (Friar) on Aug 28, 2009 at 14:15 UTC | |
Re: for loop syntax difference
by ikegami (Patriarch) on Aug 28, 2009 at 14:03 UTC | |
Re: for loop syntax difference
by Sue D. Nymme (Monk) on Aug 28, 2009 at 14:26 UTC | |
Re: for loop syntax difference
by Taulmarill (Deacon) on Aug 28, 2009 at 14:02 UTC | |
by ikegami (Patriarch) on Aug 28, 2009 at 14:05 UTC |
Back to
Seekers of Perl Wisdom