modula-2 home

  Win32 API  


Type declarations

Array types

An array type is a sequence of components of some other type.  The components of an array are distinguished by an index, which also has a specific type.  You can define arrays of arrays to represent two or greater than two-dimensional structures.

To define arrays, use:

ARRAY indextype {,indextype} OF elementtype

Each indextype must be BOOLEAN, CHAR, an enumeration type, or a subrange type.  A component of the array is defined for each combination of index values.

The elementtype can be any type, including array types.  An array type with multiple indextypes is simply shorthand for an array type with an array type as the element type.


ARRAY [1..10] OF REAL;
ARRAY [1..10], [1..10] OF REAL;


You refer to a component of an array by subscripting an array variable. Subscripting is specified as follows:


The expressions must be assignable to the index types with which the array variable was declared.  The values of the expressions must lie within the range specified by the index type.

If an index expression is outside the range of the index type, and the module was compiled with index checking turned on, the program generates a runtime error.


  • Wirth N: Programming in Modula-2, 3rd ed. Springer Verlag, Berlin, 1985.
  • Stony Brook Modula-2 documentation. Used with permission. Note: Stony-Brook M2 offers an extended syntax with features not described here. Stony Brook M2 users are encouraged to visit the Stony Brook website and to consult the Stony Brook help system.