Here's how I would recast your snippet:
I moved $product to inside the loop, since it's generally a good idea to limit the scope of variables as much as possible. This precaution is helpful only if running under strict, which I added. (With the exception of the fixing the foreach(;;) syntactic error that ysth already pointed out, the use strict line is probably the most important improvement in the version above.) Also note that the internal for loop does not execute if $number < 2.use strict; my @values = ( 7, 38, 44, 2, 0 ); for my $number (@values) { my $product = 1; $product *= $_ for 2 .. $number; print "$number Factorial is $product\n"; }
Update: Fixed the missing use strict, and added explanatory remarks.
the lowliest monk
In reply to Re: back iffing with for?
by tlm
in thread back iffing with for?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |