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 probablywondering which one to use when. Well, this section will try to clear thatdilemma up for you.
* If you have a set of statements that need to be executed a number oftimes until a certain condition is met, but you have no idea what thatnumber 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, andsome of Perl's more interesting array functions; we'll also take a look atPerl'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.| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |