home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / compares.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.5 KB  |  48 lines

  1.                                        -- Chapter 4 - Program 2
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Compares is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    package Enum_IO is new Text_IO.Enumeration_IO(BOOLEAN);
  11.    use Enum_IO;
  12.  
  13.    Index, Count           : INTEGER := 12;
  14.    Truth, Lies, Question  : BOOLEAN;
  15.  
  16. begin
  17.    Truth := Index = Count;      -- This is TRUE
  18.    Lies := Index < Index;       -- This is FALSE
  19.  
  20.                             -- Examples of all BOOLEAN operators
  21.    Question := Index =  Count;      -- Equality
  22.    Question := Index /= Count;      -- Inequality
  23.    Question := Index <  Count;      -- Less than
  24.    Question := Index <= Count;      -- Less than or equal
  25.    Question := Index >  Count;      -- Greater than
  26.    Question := Index >= Count;      -- Greater than or equal
  27.  
  28.                        -- Examples of composite BOOLEAN expressions
  29.    Question := Index = 12 and Count = 12 and Truth and TRUE;
  30.    Question := Index /= 12 or FALSE or Count > 3 or Truth;
  31.    Question := (Truth or Lies) and (Truth and not Lies);
  32.    Question := Truth xor Lies;
  33.  
  34.                        -- now for short circuit evaluation
  35.    Question := Index /= Count and then Index = 9/(Index - Count);
  36.    Question := Index = Count or else  Index = 9/(Index - Count);
  37.    Question := (Index = Count) or else (Index = 9/(Index - Count));
  38.  
  39. end Compares;
  40.  
  41.  
  42.  
  43.  
  44. -- Result of execution
  45.  
  46. --   (No output generated by this program.)
  47.  
  48.