unless statement with elsif : unless « Statement « Perl






unless statement with elsif

  

$variable = 2;

unless ($variable != 1) { 
    print "Yes, it's one.\n";
} elsif ($variable == 2) {
    print "Yes, it's two.\n";
} elsif ($variable == 3) {
    print "Yes, it's three.\n";
} elsif ($variable == 4) {
    print "Yes, it's four.\n";
} elsif ($variable == 5) {
    print "Yes, it's five.\n";
} else {
    print "Sorry, can't match it!\n";
}

   
    
  








Related examples in the same category

1.Conditional operator: The unless Modifier
2.The unless Construct
3.The unless statement is the opposite of if and executes a block unless a condition is true.
4.Using unless with regular expression
5.unless statement
6.unless statement in while
7.unless statement with else