Perl IF...ELSE 语句

Perl 教程 · 2019-02-26 19:42:14

一个 if 语句 后可跟一个可选的 else 语句,else 语句在布尔表达式为 false 时执行。

语法

语法格式如下所示:

if(boolean_expression){
   # 在布尔表达式 boolean_expression 为 true 执行
}else{
   # 在布尔表达式 boolean_expression 为 false 执行
}

如果布尔表达式 boolean_expression 为 true,则执行 if 块内的代码。如果布尔表达式为 false,则执行 else 块内的代码。

流程图

C 中的 if...else 语句

实例

#!/usr/bin/perl $a = 100; # 使用 if 语句判断布尔表达式 if( $a < 20 ){ # 布尔表达式为true时执行 printf "a 小于 20\n"; }else{ # 布尔表达式为false时执行 printf "a 大于 20\n"; } print "a 的值为 : $a\n"; $a = ""; # 使用 if 语句判断布尔表达式 if( $a ){ # 布尔表达式为true时执行 printf "a 条件为 true\n"; }else{ # 布尔表达式为false时执行 printf "a 条件为 false\n"; } print "a 的值为 : $a\n";

执行以上程序,输出结果为:

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

点击查看所有 Perl 教程 文章: https://codercto.com/courses/l/19.html

查看所有标签

Programming Computer Vision with Python

Programming Computer Vision with Python

Jan Erik Solem / O'Reilly Media / 2012-6-22 / USD 39.99

If you want a basic understanding of computer vision's underlying theory and algorithms, this hands-on introduction is the ideal place to start. As a student, researcher, hacker, or enthusiast, you'll......一起来看看 《Programming Computer Vision with Python》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具