in reply to for loop localisation bug?
withfor $n (1 .. 100)
as the former is an alias for foreach with the localization of the loop variable enabled (for the reasons that have been cited above), and the latter a straight loop counter similar in semantics as C's for() loop.for($n = 1; $n <= 100; ++$n)
This reminds me of being bitten by the following several years ago:
A C programmer would think nothing of this loop. It's a straight do/while loop with a break (or its perl equivalent) statement, right?do { ..... last if $some_condition; } while($some_other_condition);
Wrong. last/next doesn't work in this situation, because it isn't really a do/while loop, but rather a do BLOCK with a post condition (the while($some_other_condition) could just as well have been an unless() or if()).
Michael
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: for loop localisation bug?
by demerphq (Chancellor) on Dec 29, 2003 at 19:00 UTC | |
|
Re: Re: for loop localisation bug?
by calin (Deacon) on Dec 29, 2003 at 19:29 UTC |