Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Interview Prepration

by chromatic (Archbishop)
on Apr 04, 2005 at 17:53 UTC ( #444746=note: print w/replies, xml ) Need Help??


in reply to Re^2: Interview Prepration
in thread Interview Prepration

That's a really thin line to walk -- thin enough that I think it's almost meaningless and definitely more confusing than useful. Is this a for loop?

foreach ( my $i = 0; $i < 10 ; $i++ ) { print "\$i is $i\n"; }

Is this a foreach loop?

for my $user (@names) { print "Found user $user\n"; }

Replies are listed 'Best First'.
Re^4: Interview Prepration
by merlyn (Sage) on Apr 04, 2005 at 18:04 UTC
    Yes, and yes. Spelled "f-o-r", pronounced "foreach". Spelled "f-o-r-e-a-c-h", pronounced "for".

    If you start handwaving "for and foreach are the same" in front of people enough, they wonder why the variable "didn't localize in my for loop... I thought for did that!".

    It really is important to distinguish the two kinds of loops, even though 90% of the time we write "for", we prounounce it "foreach".

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Actually I think the community has selected a third way to avoid this debate, whatever it actually says in Perlsyn. The way they solved this debate is they say for LIST and 3 arg for loop or c-style for loop or if you are like me the while loop that likes to crossdress and call itself a for loop.

      I agree with chromatic, your usage, while strictly correct is confusing and misleading, especially when it leads you to obvious contortions like saying

      foreach(;1;) { }
      is a "for" loop and
      print for @list;
      is a "foreach" loop.

      Hopefully youll drop this piece of pedantry as its just confusing.

      ---
      demerphq

        I don't know what's confusing about calling something what it is, especially when there's an authoritative source that most people should have already read, or will read now. In fact, I find it more confusing when people are inventing their own terms when perfectly good terms exist.

        No, I'll stand by the reference docs here, unless I hear otherwise from the man himself.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://444746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-10-24 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (242 votes). Check out past polls.

    Notices?