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

Perl UNLESS Statement

Perl UNLESS Statement

Perl Conditional Statements Perl Conditional Statements

An unless statement consists of a Boolean expression followed by one or more statements.

Syntax

The syntax format is as follows:



unless(boolean_expression){

   # Execute when boolean_expression is false

}

If the Boolean expression boolean_expression is false, the code block inside the if statement will be executed. If the Boolean expression is true, the first group of code after the if statement ends (after the closing brace) will be executed.

Flowchart

Example

#!/usr/bin/perl

$a

=

20

;

Using an unless statement to test a Boolean expression

unless

(

$a

<

20

)

{

printf

"

a is greater than or equal to 20

\n

"

;

}

print

"

The value of a is:

$a

\n

"

;

$a

=

"

"

;

Using an unless statement to test a Boolean expression

unless

(

$a

)

{

Executed when the Boolean expression is false

printf

"

Condition a is false

\n

"

;

}

print

"

The value of a is:

$a

\n

"

;

Running the above program, the output is:



a 大于等于 20

a 的值为 : 20

条件 a 为 false

The value of a is:

Perl Conditional Statements Perl Conditional Statements