John W. Krahn wrote:

Chas Owens wrote:

On 4/19/07, Jenda Krynicky <[EMAIL PROTECTED]> wrote:

From: "Chas Owens" <[EMAIL PROTECTED]>

foreach is dead, long live for.

I would myself use "for" for the C-style loops

And this is why.  As long as people think "well, I have foreach which
is for iterating and for which is for C-style loops" they will
continue to write C-style loops.  C-style loops are bad.  They are
there for backwards compatibility.  I can't think of a single for loop
that isn't better written as a range based for loop or while loop. For
instance

standard range based loop
for (my $i = 0; $i < 10; $i++) {}
for my $i (0 .. 9) {}

How about:

for ( my $i = 0; $i < 10; $i += 3 ) {}

foreach my $i ( ? .. ? ) {}


And

for (my $elem = $doc->firstChild; $elem; $elem = $elem->nextSibling) {
 :
}

Rob

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


Reply via email to