| Next | Program
Repair Shop ![]() |
190 |
The C-style for loop, which we've already discussed:
for ($i=0; $i <= $#array; $i++) {
# do something with $array[$i]
}
Better:
for my $element (@array) {
# do something with $element
}
If you need the value of $i inside the loop, $#array is a good choice:
for my $i (0 .. $#array) {
# do something with $i
}
| Next | ![]() |
Copyright © 2002 M. J. Dominus |