无涯教程-Perl - if...elsif...else语句函数

if 语句后可以跟可选的 elsif ... else 语句,这对于使用单个if ... elsif语句测试各种条件非常有用。

if...elsif...else - 语法

Perl编程语言中的 if ... elsif...else语句的语法是-

if(boolean_expression 1) {
   # Executes when the boolean expression 1 is true
} elsif( boolean_expression 2) {
   # Executes when the boolean expression 2 is true
} elsif( boolean_expression 3) {
   # Executes when the boolean expression 3 is true
} else {
   # Executes when the none of the above condition is true
}

if...elsif...else - 示例

#!/usr/local/bin/perl
 
$a=100;
# check the boolean condition using if statement
if( $a  ==  20 ) {
   # if condition is true then print the following
   printf "a has a value which is 20\n";
} elsif( $a ==  30 ) {
   # if condition is true then print the following
   printf "a has a value which is 30\n";
} else {
   # if none of the above conditions is true
   printf "a has a value which is $a\n";
}

在这里,我们使用等于运算符==,用于检查两个操作数是否相等。如果两个操作数相同,则返回true,否则返回false。

a has a value which is 100

Perl 中的 if...elsif...else语句函数 - 无涯教程网无涯教程网提供if 语句后可以跟可选的 elsif ... else 语句,这对于使用单个if ... elsif 语句测试各...https://www.learnfk.com/perl/perl-if-elsif-statement.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值