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> array constant pp 90</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 Array Constant                                                        pp 90


   TYPE
         Suit = Array [1..4] of String [8] ;
   CONST
         Card : Suit = ('Hearts', 'Diamonds', 'Clubs', 'Spades') ;
   BEGIN
         WriteLn (Card[1]) ;           { 'Hearts' is displayed }
   END.


 Notes:  First, an array type is defined.  'SUIT' is defined as a string
         array type made up of four elements, each being eight bytes long.

         Next, an array constant type is defined.  'CARD' is a four element
         string array constant that contains the four card suits.  The 'CARD'
         array subscript is 1..4 because 'SUIT' is defined as such.


   TYPE
         Compass   = (North, South, East, West) ;
         Direction = Array [Compass] of String [5] ;
   CONST
         Heading   : Direction = ('N', 'S', 'E', 'W') ;
   BEGIN
         WriteLn (Heading[North]);    { 'N' is displayed }
   END.


 Notes:  'DIRECTION' is defined as a string array type made up of four
         elements, each being five bytes long.  The array subscript is
         North, South, East, West instead of 1,2,3,4 because 'DIRECTION'
         is defined as an array of [Compass] subscript type.

         'HEADING' is a four element string array constant that contains the
         four letters N,S,E,W.  The 'HEADING' array subscripts are North,
         South, East, and West.


   TYPE
         Cube = Array [0..1, 0..1, 0..1] of Integer ;
   CONST
         Maze : Cube = (((0,1), (2,3)), ((4.5), (6,7))) ;


         (*
         Maze [0,0,0] = 0
         Maze [0,0,1] = 1
         Maze [0,1,0] = 2
         Maze [0,1,1] = 3
         Maze [1,0,0] = 4
         Maze [1,0,1] = 5
         Maze [0,1,1] = 6
         Maze [1,1,1] = 7
         *)


 Notes:  Multi-dimensional array constants are defined by enclosing each
         dimension in separate sets of parentheses.
         The innermost constants correspond to the rightmost dimensions.

See Also: Array

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