Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Hard syntax error or disambiguable parsing?

by rovf (Priest)
on Jan 29, 2009 at 09:02 UTC ( [id://739825]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hard syntax error or disambiguable parsing?
in thread Hard syntax error or disambiguable parsing?

for $i ( 0 .. 5 ) is not a foreach loop

May I ask you in what way

for $i ( 0 .. 5 )
and
foreach $i ( 0 .. 5 )
differ, according to your opinion? perlsyn says The "foreach" keyword is actually a synonym for the "for" keyword, so I don't see how you came to the idea that the for loop your mention, would not be a foreach loop. Did I miss something here?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^4: Hard syntax error or disambiguable parsing?
by ikegami (Patriarch) on Jan 29, 2009 at 13:40 UTC

    Did I miss something here?

    You probably think the ".." in "for[each] $i ( 0 .. 5 )" is the range operator and that it creates a list of 6 elements. It's not, and no list of 6 elements is created.

    perlsyn distinguishes between For Loops ("C"-style For Loops) and Foreach Loops (List Iteration Loops), but "for[each] $i ( 0 .. 5 )" is neither. It's actually a Counting Loop like FOR ... NEXT in BASIC.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found