in reply to Re: Re: (jeffa) Re: (s)coping with foreach
in thread (s)coping with foreach
I know, but... hmmm.
Getting back to your questions...
Let's rewrite your loop:
my $var=0; { $var=1; while ($var < 10) { print "$var"; $var++; } } print "\n$var \n";
The for loop adds to $var, then checks condition, then breaks loop. It doesn't say would I break the condition if I added one to $var, so $var is 10.
Also, you don't declare $var as being local to the loop. So, look at this:
my $var=0; foreach (my $var=1; $var < 10; ++$var){ print $var; } print "\n$var \n";
Or, as written above:
my $var=0; { my $var=1; while ($var < 10) { print "$var"; $var++; } } print "\n$var \n";
Seem clearer now?
cLive ;-)
|
|---|