Perl Programming Page 6 - Perl 101 (Part 3) - Looping The Loop |
The "for" loop also comes with a bunch of control statements, which can beused to modify its behaviour. We've listed the important ones below,together with examples: next: The "next" statement allows you to jump to the next iteration of the loopwithout executing the remaining statements of the current iteration.Consider this: Here's what it looks like: As you can see, 9 is missing - this is because when the value of $counterhits 9, Perl uses the "next" statement to skip to the next iteration of theloop, and so 9 never gets printed. last: The "last" statement is used to exit the loop completely. Take a look: And here's the output: redo: And finally, the redo statement lets you restart a particular iteration ofthe loop: In this case, here's what you'll see:
This article copyright Melonfire 2000. All rights reserved.
blog comments powered by Disqus |