*/
Do you receive the Programmer's Heaven newsletter? If not, why not subscribe?
*/

View \SUBRANGE.PAS

Getting Started with the Pascal tutorial, source

Submitted By: WEBMASTER
Rating: (Not rated) (Rate It)


(* Chapter 8 - Program 2 *)
program Scaler_Operations;

type Days = (Mon,Tue,Wed,Thu,Fri,Sat,Sun);
     Work = Mon..Fri;
     Rest = Sat..Sun;

var  Day      : Days; (* This is any day of the week *)
     Workday  : Work; (* These are the the working days *)
     Weekend  : Rest; (* The two weekend days only *)
     Index    : 1..12;
     Alphabet : 'a'..'z';
     Start    : 'a'..'e';

begin  (* main program *)
(*  The following statements are commented out because they contain
    various errors that will halt compilation.

   Workday := Sat;   Sat is not part of Workday's subrange.
   Rest := Fri;      Fri is not part of Weekend's subrange.
   Index := 13;      Index is only allowed to go up to 12,
   Index := -1;        and down to 1.
   Alphabet := 'A'   Alphabet, as defined, includes only the
                       lower case alphabet.
   Start := 'h'      h is not in the first five letters.

   End of commented out section.  *)


   Workday := Tue;
   Weekend := Sat;
   Day := Workday;
   Day := Weekend;
   Index := 3+2*2;
   Start := 'd';
   Alphabet := Start;
                             (* since Alphabet is "d"    *)
   Start := Succ(Alphabet)(* Start will be 'e'        *)
   Start := Pred(Alphabet)(* Start will be 'c'        *)
   Day := Wed;
   Day := Succ(Day)(* Day will now be 'Thu' *)
   Day := Succ(Day)(* Day will now be 'Fri' *)
   Index := Ord(Day); (* Index will be 4 (Fri = 4) *)
end. (* of main program *)

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.