The condition at the end running once before the test is something I've long known, since the Pascal days. That for doesn't is not something I've thought about.
$value= "global";
do { print "Inside block: $value\n" }
for (my $value= 5; $value < 7; ++$value);
does not compile, so whether the loop variable is set first or later or what the scope is is moot. For the list form,
$_= 1;
do { print "Inside block: $_\n" }
for (5..7);
It is intuative that it work the same way, one iteration per item in the list, and you can't use a variable, e.g.
do { print "Inside block: $value\n" }
for my $value (5..7);
doesn't compile either. So variable scope issues are avoided.
Interesting.
—John |