Perl 中的unless-else语句

Perl 中的unless-else语句,类似于unless 语句Perl 中的unless-else语句与if-else 语句相反。在except-else中,如果条件为false,执行内部语句,如果条件为true,则执行else内的语句。

unless(condition) {
   #These statements would execute
   #if the condition is false.
   statement(s);
}
else {
   #These statements would execute
   #if the condition is true.
   statement(s);
}

示例如下:

#!/usr/local/bin/perl

printf "Enter any number:";
num = <STDIN>;
unless(num>=100) {
   #This print statement would execute,
   #if the given condition is false
   printf "num is less than 100\n";
}
else {
   #This print statement would execute,
   #if the given condition is true
   printf "number is greater than or equal to 100\n";
}

输出:

Enter any number:100
number is greater than or equal to 100

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程