in reply to for vs foreach
I'm the complete opposite. I can't remember the last time that I used for. It always seems to me that for iteraring over a list, the foreach syntax is more natural. I find
foreach (@array) { # do someting with $_ }
far easier to follow than
for ($i = 0; $i < @array; ++$i) { # do something with $array[$i] }
If, for some reason you need the array index for some calculation, then you can use
foreach $i (0 .. $#array) { # do something with $array[$i] }
Of course, if you're really keen on saving keystrokes you can always spell foreach as for.
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: for vs foreach
by vkonovalov (Monk) on Jul 14, 2000 at 14:08 UTC |