Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> if/then/else conditional testing pp 57</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 IF/THEN/ELSE                Conditional Testing                       pp 57


 Define:  Conditional execution dependent upon a Boolean condition.

 Purpose: Allow execution of statements or blocks of statements depending
          upon the results of a Boolean test condition.

 Notes:   The If statement specifies that a statement be executed only
          if a certain condition is True.  If False, then either no
          statement or the statement following the reserved word Else
          is executed.

          Else must not be followed by a semi-colon.

          The Else clause generally belongs to the last If
          statement which has no Else part.


 ----------------------------------------------------------------------------


 Usage:
       BEGIN

          If 1 < 2 Then WriteLn ('1');  { Execute because 1 < 2 is True     }

          If (1+1) < (2+2)              { Execute because 2 < 4 is True     }
             Then Begin                 { Start of compound statements      }
             WriteLn ('OK');            { Executed because 2 < 4 is True    }
             End                        { Note there is no semi-colon       }

             Else                       { Execute only if 2 < 4 is False    }
             WriteLn ('Not OK');        { This would execute instead of OK  }

       END.

See Also: Case

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson