in reply to For Statement & Letters
my $start_number = 1; my $end_number = 10; for (my $i=$start_number; $i<=$end_number; $i++) { print "\$i = $i\n"; }
with the much briefer, clearer (IMHO) and more robust (less prone to bugs):
foreach my $i (1 .. 10) { print "\$i = $i\n"; }
One of the nice features of range operator is that it operates on letters as well as numbers:
foreach my $i ('A' .. 'D') { print "\$i = $i\n"; }
Perl documentation seems to be down right now, so hopefully the above links function properly, but if not, you should be able to use the above information to navigate your local copies of the documentation. As a side note, see Writeup Formatting Tips, in particular please wrap posted code in <code> tags to aid in readability.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: For Statement & Letters
by dsheroh (Monsignor) on Jan 28, 2010 at 08:26 UTC |