企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Perl 中的`unless-elsif`语句 > 原文: [https://beginnersbook.com/2017/02/unless-elsif-else-statement-in-perl/](https://beginnersbook.com/2017/02/unless-elsif-else-statement-in-perl/) 当我们需要检查多个条件时,使用`unless-elsif-else`语句。在这个声明中,我们只有一个`unless`和一个`else`,但我们可以有多个`elsif`。这是它的样子: ```perl unless(condition_1){ #These statements would execute if #condition_1 is false statement(s); } elsif(condition_2){ #These statements would execute if #condition_1 & condition_2 are true statement(s); } elsif(condition_3){ #These statements would execute if #condition_1 is true #condition_2 is false #condition_3 is true statement(s); } . . . else{ #if none of the condition is met #then these statements gets executed statement(s); } ``` #### 例 ```perl #!/usr/local/bin/perl printf "Enter any number:"; $num = <STDIN>; unless( $num == 100) { printf "Number is not 100\n"; } elsif( $num==100) { printf "Number is 100\n"; } else { printf "Entered number is not 100\n"; } ``` **输出:** ```perl Enter any number:101 Number is not 100 ```