Questions about this topic? Sign up to ask in the talk tab.

Perl/Basics/Boolean Logic/Statements/If

From NetSec
Revision as of 02:42, 16 July 2012 by AlizaLorenzo (Talk | contribs) (Created page with "An '''if''' statement may have 3 types of clauses: '''if''','''elsif''', and '''else'''. For the below example, assume that the $age scalar is passed as a command line argument: ...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

An if statement may have 3 types of clauses: if,elsif, and else. For the below example, assume that the $age scalar is passed as a command line argument:

 
if (int($age) == $age) {  #Making sure it's an integer.
    if ($age < 18) {      #If the age is less than 18:
        print "You must be at least 18 to view this.\n";
    } elsif ($age < 21) { # If the age is more than 18, but less than 21:
        print "Because you are under 21, some features may be restricted.\n";
    } else {              # If none of the conditions have been met:
        display_content();
    }
}