if, else
if, else
Perl
$n = 2; if ( 0 == $n ) { print "no hits\n" } elsif ( 1 == $n ) { print "1 hit\n" } else { print "$n hits\n" # 2 hits } unless ( 0 != $n ) { print "no hits\n" } else { print "$n hits\n" # 2 hits } print "$n hits\n" if ($n > 1); # 2 hits print "$n hits\n" unless ($n <= 1) # 2 hits
Ruby
n = 2 if 0 == n print "no hits\n" elsif 1 == n print "1 hit\n" else print "#{n} hits\n" # 2 hits end unless 0 != n print "no hits\n" else print "#{n} hits\n" # 2 hits end print "#{n} hits\n" if n > 1 # 2 hits print "#{n} hits\n" unless n <= 1 # 2 hits
PHP
<?php $n = 2; if ( 0 == $n ) print "no hits\n"; elseif ( 1 == $n ) print "1 hit\n"; else print "$n hits\n" # 2 hits ?>
Python
n = 2 if 0 == n: print "no hits" elif 1 == n: print "1 hit" else: print n, "hits" # 2 hits