Perl 中的 if_else 语句函数

首页 / Perl入门教程 / Perl 中的 if_else 语句函数

Perl if语句后面可以跟随可选的else语句,该语句在布尔表达式为false时执行。

Perl if else - 语法

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

if(boolean_expression) {
   # statement(s) will execute if the given condition is true
} else {
   # statement(s) will execute if the given condition is false
}

Perl if else - 流程图

Perl if...else statement

Perl if 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 is less than 20\n";
} else { 
   # if condition is false then print the following
   printf "a is greater than 20\n";
}
print "value of a is : $a\n";

$a="";
# check the boolean condition using if statement
if( $a ) {
   # if condition is true then print the following
   printf "a has a true value\n";
} else {
   # if condition is false then print the following
   printf "a has a false value\n";
}
print "value of a is : $a\n";

执行上述代码时,将生成以下输出-

无涯教程网

a is greater than 20
value of a is : 100
a has a false value
value of a is : 

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

人工智能基础课 -〔王天一〕

从0开始学游戏开发 -〔蔡能〕

React实战进阶45讲 -〔王沛〕

面试现场 -〔白海飞〕

人人都能学会的编程入门课 -〔胡光〕

职场求生攻略 -〔臧萌〕

说透数字化转型 -〔付晓岩〕

反爬虫兵法演绎20讲 -〔DS Hunter〕

超级访谈:对话汤峥嵘 -〔汤峥嵘〕

好记忆不如烂笔头。留下您的足迹吧 :)