Perl if 语句由一个布尔表达式和一个或多个语句组成。
Perl编程语言中的 if 语句的语法是-
if(boolean_expression) { # statement(s) will execute if the given condition is true }
如果布尔表达式的值为 true ,则将执行 if 语句中的代码块。
#!/usr/local/bin/perl $a=10; # 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"; } 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"; } print "value of a is : $a\n";
第一个IF语句使用小于运算符(<),该运算符比较两个操作数,如果第一个操作数小于第二个操作数,则返回true,否则返回false。
a is less than 20 value of a is : 10 value of a is :
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)