标签:
if 系列语句有一下几种:
if语句语法:
if ( some_expression ){ true_statement1; true_statement2; ... } next_statment;程序执行到这里时,如果 some_expression 为真,则执行大括号内的其它语句;如果 some_expression 为假,程序则跳过大括号内的语句块,直接执行 next_statment。
if else 语句语法:
if ( some_expression ){ true_statement1; true_statement2; ... } else{ false_statement1; false_statement2; .... } next_statment; ...
if ( some_expression_one ){ one_true_statement1; one_true_statement2; } elsif ( some_expression_two ){ two_true_statement1; two_true_statement2; } elsif ( some_expression_three ){ three_true_statement1; three_true_statement2; } else{ all_false_statement1; all_false_statement2; } next_statment; ...
#!/usr/bin/perl $number=<>; chomp($number); if($number > 0){ print ("puls\n"); } else{ if ($number < 0){ print ("minus\n"); } else{ print ("zero\n"); } }
unless语法:
unless(some_expression){ false_statement1; false_statement2; } unless( some_expression){ false_statement1; false_statement2; } else{ true_statement1; true_statement2; }示例:
#!/usr/bin/perl $number=<>; chomp($number); unless($number != 0){ print ("zero\n"); } else{ unless ($number < 0){ print ("plus\n"); } else{ print ("minus\n"); } }
标签:
原文地址:http://blog.csdn.net/u011641885/article/details/46052515