From: darren chamberlain <[EMAIL PROTECTED]>
Date: Thu, 21 Nov 2002 09:17:11 -0500
* Chris Devers <[EMAIL PROTECTED]> [2002-11-20 16:19]:
> On Wed, 20 Nov 2002, darren chamberlain wrote:
> > I think the answer is to use a C-style for loop:
> >
> > for (my $i = 0; $i < $#array; $i++) {
> > # $i is your "iterator"
> > # $array[$i] is the "current" element
> . . .
> Is there any significant difference, beyond style preference?
My C-style for loop (above) is identical to:
my $iterator = 0;
while ($iterator < $#array) {
$iterator++;
do "stuff";
}
. . .
Not quite. It looks like the 'while' loop skips element 0, but the
'for' version skips the last one. I tend to prefer "$i < @array" over
"$i <= $#array" in loop tests, because I think it is more natural and
less prone to such problems.
-- Bob "Fencepost" Rogers
http://rgrjr.dyndns.org/
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm