Example five - if structures


#Example five - example of IF structures.
# by Al Bento

#variables used in the example

$a = "this is example";
$b = 3;
$c = 3;
$d = 3;
++$c;     # equivalent to $c = $c + 1

# a simple IF structure

if ($b > $c)   {
       print "b is greater than c\n";
       } else {
       print "c is greater or equal to b\n";
}
print "\n";

# a more interesting one

if ($b > $d    &&   $c > $d) {
       print "b and c are greater than $d\n";
       } else {
        print "either b or c is smaller or equal to $d\n";
}
print "\n";

# a variation from above

if ($b > $d && $c > $d)  {
       print "b and c are greater than $d\n";
       }   elsif ($c > $d) {
       print "c is greater than $d, but b is not\n";
       }   else {
       print "either b or c is smaller or equal to $d\n";
}

download the script


This page is maintained by Al Bento who can be reached at abento@ubmail.ubalt.edu. This page was last updated on June 15, 1997. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.