Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Perl until Loop

Perl until Loop

Perl Loops Perl Loops

The until statement repeatedly executes a statement or group of statements while the given condition is false.

until can be translated as **"unless"**.

Syntax

The syntax format is as follows:



until(condition)

{

   statement(s);

}

Here, statement(s) can be a single statement or a block of several statements.

condition can be any expression; the loop executes when the condition is false. When the condition is true, program flow continues with the next statement immediately after the loop.

Flowchart

The until Loop in Perl

In the diagram,until The key point of the loop is that it may not execute even once. When the condition is true, the loop body is skipped and the next statement immediately after the while loop is executed directly.

Example

#!/usr/bin/perl

$a

=

5

;

Executing the until loop

until

(

$a

10

)

{

printf

"

The value of a is:

$a

\n

"

;

$a

=

$a

1

;

}

In the program, the loop body executes while the variable $a is less than 10, and exits the loop when the variable $a is greater than 10.

Running the above program, the output is:



a 的值为 : 5

a 的值为 : 6

a 的值为 : 7

a 的值为 : 8

a 的值为 : 9

a 的值为 : 10

Perl Loops Perl Loops