home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / tutorial / programs / subrange.mod < prev    next >
Text File  |  1993-03-14  |  2KB  |  47 lines

  1.                                         (* Chapter 10 - Program 2 *)
  2. MODULE Subrange;
  3.  
  4. TYPE Days = (mon,tue,wed,thu,fri,sat,sun);
  5.      Work = [mon..fri];
  6.      Rest = [sat..sun];
  7.  
  8. VAR  Day      : Days;  (* This is any day of the week *)
  9.      Workday  : Work;  (* These are the working days  *)
  10.      Weekend  : Rest;  (* The two weekend days only   *)
  11.      Index    : [1..12];
  12.      Alphabet : ['a'..'z'];
  13.      Start    : ['a'..'e'];
  14.  
  15. BEGIN    (* Main program *)
  16. (*  The following statements are commented out because they
  17.     contain various errors that will halt compilation.
  18.  
  19.    Workday := sat;   sat is not part of Workday's subrange.
  20.    Rest := fri;      fri is not part of Rest's subrange.
  21.    Index := 13;      Index is only allowed to go up to 12,
  22.    Index := -1;        and down to 1.
  23.    Alphabet := 'A';  Alphabet, as defined, includes only the
  24.                        lowercase alphabet.
  25.    Start := 'h';     h is not in the first five letters.
  26.  
  27.    End of the commented out section of program.
  28. *)
  29.  
  30.    Workday := tue;
  31.    Weekend := sat;
  32.    Day := Workday;
  33.    Day := Weekend;
  34.    Index := 3 + 2 * 2;
  35.    Start := 'd';
  36.    Alphabet := Start;
  37.                             (* Since Alphabet is 'd'     *)
  38.    INC(Alphabet);           (*   and now 'e'             *)
  39.    Start := Alphabet;       (* Start will be 'e'         *)
  40.    DEC(Start,2);            (* Start will be 'c'         *)
  41.    Day := wed;
  42.    INC(Day);                (* Day will now be 'thu'     *)
  43.    INC(Day);                (* Day will now be 'fri'     *)
  44.    Index := ORD(Day);       (* Index will be 4 (fri = 4) *)
  45.  
  46. END Subrange.
  47.