http://www.perlmonks.org?node_id=211102


in reply to for loops

I think it would be useful to show an additional way the for loop can be used. Although the C-like for loop can do the same thing, I find myself using the one below more and more.

for $countdown (10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 'Liftoff!') { print $countdown, "\n"; } for $y (0..$x) { print $array[$y], "\n"; } for (@array) { s/value1/value2/ } # Substitues value2 for value 1.

bW

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.