Perl Until Loop/h1

Perl until loop Perl loop

An until statement repeats a statement or group of statements when a given condition is false.

Grammar

The syntax format looks like this:

until(condition)
{
   statement(s);
}

Here, statement(s) can be a separate statement or a block of code consisting of several statements. Condition can be any expression that executes a loop when the condition is false.

When the condition is true, the program flow continues to execute the next statement immediately after the loop.

Flow chart

Perl until loop

In the chart, the key point of the until loop is that the loop may not execute once. When the condition is true, the loop body is skipped and the next statement immediately following the while loop is executed.

Instance

#!/usr/bin/perl

$a = 5;

# 执行 until 循环
until( $a > 10 ){
   printf "a 的值为 : $a\n";
   $a = $a + 1;
}

The program executes the loop body $a the variable is less than 10 and exits the loop when the variable $a is greater than or equal to 10.

The above procedure is performed and the output is:

a 的值为 : 5
a 的值为 : 6
a 的值为 : 7
a 的值为 : 8
a 的值为 : 9
a 的值为 : 10

Perl until loop Perl loop