Chas. Owens wrote:
> On Thu, Apr 3, 2008 at 7:29 PM, Ryan <[EMAIL PROTECTED]> wrote:
>> I know they are both the same, I just want to know why we have both.
> snip
> 
> Because originally they meant different things.  The for loop was a
> c-style loop and the foreach loop was an iterator.  Eventually it was
> realized that the iterator style was a better loop and typing foreach
> every time was annoying, so they made for able to do both types of
> loops.  In order to keep as much code running as possible the foreach
> loop was kept.  Just ignore foreach.

Hmm. IYHO. It sounds as though you would like to contract all of the
Perl language words into single characters if possible to save typing.

Although 'foreach' is more useful, I think it's it's far more likely
that someone realized that the two could be distinguished by context and
needn't have different symbols, so the two were made equivalent.

I preserve 'foreach' to iterate over a list, and use 'for' for C-style
for loops and single elements, like:

  for ($string) {
    s/^\s+//;
    s/\s+$//;
  }

My rule: use the one that best describes in English the function it's
performing.

Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to