O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

while Loops

The various if statements in Perl are all used to control execution by branching to differ-ent parts of a script. The second way to control execution is through the use of a loop, where the same block of Perl statements are executed repeatedly, stopping only when some condition is met. Perl has two general sets of loops, both of which do roughly the same thing: while loops, which loop until a condition is met, and for loops, which loop a certain number of times. Generally, whiles can be rewritten to emulate fors, and vice versa, but conceptually each one seems to lend itself to specific situations better than the other.

We'll start with the while loops, of which Perl has three: while, dowhile, and until.

while

You've already seen ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required