in reply to for vs foreach

This is my thoughts. In perl 4 for and foreach had different syntax. For was like its C counter part, and foreach had the form you are using. In perl 5 these two became interchangeable. There is a good posibilty that they are now the same code with different names for backward compatability. That is my thoughts on the subject. If anyone has found any documentation that would be great.

Replies are listed 'Best First'.
RE: Re: for vs foreach
by merlyn (Sage) on Jul 14, 2000 at 18:33 UTC
    The words for and foreach have always been interchangable back to Perl version 0.

    But for purposes of documentation, we call a for loop the thing that acts very C-like (with three expressions separated by semicolons), and foreach is reserved for the csh-like thing (with a variable to walk through a list).

    In my experience, people start out writing a lot of for-loops, but end up writing many more foreach loops. Of course, people spell it "f-o-r" and pronounce it "foreach".

    -- Randal L. Schwartz, Perl hacker

      Thanks for the info. I probably didn't realize they were then same until perl 5 came out.