Perl 101 (Part 3) - Looping The Loop - So Many Choices... (
Page 9 of 9 )
Now that you know all about Perl's control structures, you're probably
wondering which one to use when. Well, this section will try to clear that
dilemma up for you.
* If you have a set of statements that need to be executed a number of
times until a certain condition is met, but you have no idea what that
number is, the "while" and "until" loops are a good bet.
* If you have a set of statements that need to be executed at least once,
the "do-while" and "do-until" loops are the ones to go with.
* If you need to execute a set of statements a specific number of times,
pick the "for" loop and don't think twice!
* If you need to process every element of an array, go with the "foreach"
loop.
Next time, we'll be teaching you a little more about array variables, and
some of Perl's more interesting array functions; we'll also take a look at
Perl's file manipulation capabilities.
What will you do until then? Well, they're bound to be showing re-runs of
"Friends" on your local cable channel...
This article copyright Melonfire 2000. All rights reserved.