in reply to Re^9: eof not recognised when applying diamond operator to invocation arguments?
in thread eof not recognised when applying diamond operator to invocation arguments?

I mean, there are three sections in the parenthesis

So you choose to make the C-style for loop look difference from the others because it looks different? No, that doesn't make much sense to me.

  • Comment on Re^10: eof not recognised when applying diamond operator to invocation arguments?

Replies are listed 'Best First'.
Re^11: eof not recognised when applying diamond operator to invocation arguments?
by Argel (Prior) on Jan 17, 2011 at 22:35 UTC
    Good grief!! Even the Perl documentation makes the distinction between the two: For Loops and Foreach Loops. Yes, it does go on to mention that "foreach" is a synonym for "for", but the documentation starts off by using "for" to describe the C-style form of "(;;)" and "foreach" to describe the Perl-style form of "$var (list)". And that includes separate, distinct entries in the table of contents -- i.e. they are listed as two different styles of looping, which is only clarified under "Foreach". So I'm perfectly in line with how the Perl documentation describes them. Not saying you guys are wrong -- but the original point was that it's a stylistic choice.

    My point about discouraging "for" loops was if the two were actually two distinct looping styles (i.e. that "foreach" was not a synonym for "for", so that "for" could only be used for C-style for loops). Sorry if there was any confusion over that.

    Elda Taluta; Sarks Sark; Ark Arks

      Good grief!! Even the Perl documentation makes the distinction between the two:

      I didn't say what you do makes no sense; I said the reason you gave makes no sense. It doesn't mean there are no other reasons that do make sense.

      but the documentation starts off by using "for" to describe the C-style form of "(;;)

      C-style loops are almost always used as for loops, so that's pretty accurate (although they are really just while loops.)

      and "foreach" to describe the Perl-style form of "$var (list)".

      Actually, the documentation isn't as clear as your purport it to be. It appears that section was written to describe that syntax, but it says "The foreach loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn." for VAR (EXPR..EXPR) doesn't match that definition.

      The Perl documentation is one of those that seem to forget about Perl-style for loops.

      So I'm perfectly in line with how the Perl documentation describes them.

      But I'm asking about that case that's not documented! So we've looped back to here.

      My point about discouraging "for" loops was if the two were actually two distinct looping styles

      If the two were actually two distinct looping styles, ...? Part of that sentence seems to be missing.

        Good point about the syntax, though the end result is the same -- "for" and "foreach" are given separate treatment.

        Regarding Perl style "for" loops, I think in general, if I was using the "(;;)" format then I would use "for" and if I was using the "$var (list)" format I would use foreach. But there could be exceptions and I'm not sure how to articulate it any better than in my first attempt. (^_^;) :-/

        Regarding the missing text, this is what I wrote:

        My point about discouraging "for" loops was if the two were actually two distinct looping styles (i.e. that "foreach" was not a synonym for "for", so that "for" could only be used for C-style for loops). Sorry if there was any confusion over that.
        If you see all of that then what I meant was "my comment above about discouraging the use of 'for' loops was predicated on restricting "for" loops to only the C-style (;;) syntax".

        Elda Taluta; Sarks Sark; Ark Arks