Problems? Is your data what you think it is? | |
PerlMonks |
Re: for() or foreach() ?by ikegami (Patriarch) |
on Jul 14, 2006 at 15:46 UTC ( [id://561243]=note: print w/replies, xml ) | Need Help?? |
Counting ("for") loops and iterating ("foreach") loops can use the for and the foreach keywords interchangably, as documented in perlsyn. Personally, I use "for" for counting ("for") loops, and "foreach" for iterating ("foreach") loops. Some people use "for" unconditionally because it is shorter. Iterating ("foreach") loops:
Also iterating ("foreach") loops:
Counting ("for") loops:
Also counting ("for") loops:
* — Loops of the form for/foreach [...] ($num1..$num2) are optimized into a counting ("for") loop.
In Section
Seekers of Perl Wisdom
|
|