Perl

  1. Home
  2. Computing & Technology
  3. Perl

until loop - Beginning Perl Tutorial, Control Structures

How to use an until loop in Perl

From About.com

Next: Examples of Perl's until loop

Perl's until loop is used to loop through a designated block of code until a specific condition is evaluated as true. It is the logical opposite of the while loop.

until (expression) {
...
}
Perl starts the block by evaluating the expression inside the parenthesis. If the expression evaluates as false the code is executed, and will continue to execute in a loop until the expression evaluates as true. If the expression initially evaluates to true, the code is never executed and the code block will be skipped entirely.

The until loop process looks something like this when you break down each of the steps:

  1. Evaluate the initial expression.
  2. Does the test evaluate to false? If so, continue, otherwise exit the until loop.
  3. Execute the code block inside the until loop.
  4. Return to step 2.
Unlike the for loop, the until loop does not have a self-contained way to alter the initial expression. Be careful that your Perl script does not wind up in a continuous until loop and lock up or crash.

Next: Examples of Perl's until loop

Explore Perl

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Perl

  1. Home
  2. Computing & Technology
  3. Perl
  4. Perl Tutorials
  5. Perl until loop tutorial - Control structures in Perl, learn how to use an until loop.

©2009 About.com, a part of The New York Times Company.

All rights reserved.