1. Computing

until loop - Beginning Perl Tutorial, Control Structures

How to use an until loop in Perl

From , former About.com Guide

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

©2013 About.com. All rights reserved.