Perl UNLESS Statement

Perl 条件语句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){
   # 在布尔表达式 boolean_expression 为 false 执行
}

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

Flowchart

Example

#!/usr/bin/perl $a = 20; # Use the unless statement to test a boolean expression unless( $a < 20 ){ # Executed when the boolean expression is false printf "a is greater than or equal to 20\n"; } print "The value of a is:$a\n"; $a = ""; # Use the unless statement to test a boolean expression unless ( $a ){ # Executed when the boolean expression is false printf "The condition a is false\n"; } print "The value of a is:$a\n";

After executing the above program, the output result is:

a 大于等于 20
a 的值为 : 20
条件 a 为 false
a 的值为 :

Perl 条件语句Perl Conditional Statements

Other Extensions