Learn Pascal
5D - Multidimensional Arrays

You can have arrays in multiple dimensions:
     type
        datatypeidentifier = array [enum_type1, enum_type2] of datatype;

The comma separate the dimensions, and referring to the array would be like:
     a [5, 3]

2-dimensional arrays are useful for programming board games. A tic tac toe board should have these type and variable declarations:

   type
      StatusType = (X, O, Blank);
      BoardType = array[1..3,1..3] of StatusType;
   var
      Board : BoardType;
You should initialize the board with:
   for count1 := 1 to 3 do
      for count2 := 1 to 3 do
         Board[count1, count2] := Blank;

You can go into even higher dimensions. I don't know why you'd need a 50-dimension array, though. Even space, according to string theory, only has 10 or 26 dimensions!


Previous lesson

Next lesson

Contents

Index

e-mail me


taoyue@mit.edu
Copyright © 1997-2001 Tao Yue. All rights reserved.