ARRAY Data Type


Used to declare an array variable.

Syntax 1

ARRAY [dimension][, dimension]... OF data-type array-id

Syntax 2

data-type array-id [dimension] [, dimension]...

Syntax 3

ARRAY[dimension] OF ARRAY [dimension] OF data-type array-id
Variable Description
dimension An INTEGER expression that specifies the size of the array. The expression is evaluated at runtime.
data-type The data type you want the elements in the array to have.
array-id An identifier that specifies the name of the array.


  • Often you need to group several pieces of data together. 4Test uses the ARRAY and LIST compound data types to do this. Use the ARRAY data type to group together data values, all of which must have the same type. Specify the type and number of elements when you declare the array.

  • Arrays are made up of elements that are grouped in a hierarchy. Each level of the hierarchy is called a dimension. Each dimension holds a fixed number of either elements or sub-arrays. The leaf nodes of the hierarchy, which are in the last dimension specified, contain elements; the other dimensions hold sub-arrays. Consider the following array specification:
    ARRAY[2][3][4] OF INTEGER MyArray
    In this array there are two sub-arrays at level one, three sub-arrays at level two, and 4 elements in each of the level two sub-arrays. Since each of the level-one sub-arrays contains three sub-arrays, and each of these six level-two sub-arrays contains four elements, MyArray contains 24 elements.
  • Array size must be between 1 and 2147483647 (MAXINT).

  • To refer to an element in a one-dimensional array, use the array name and an expression in square brackets that evaluates to the position of the element in the array.

  • To refer to an element in a multi-dimensional array, use the array name followed by two or more expressions in brackets.
    • The last expression refers to the element.

    • The preceding expressions refer to the arrays and sub-arrays containing the element.

    • A reference to an array must account for each of the specified dimensions.

  • For example, array2[2,10,5] refers to an element in a three-dimensional array. Alternatively, array2[2][10][5] refers to the same element. 4Test treats each dimension of a multi-dimensional array as a sub-array of the larger array.

  • You can initialize an array using the LIST constructor ({}). When you use braces in a declaration of an array object, 4Test implicitly casts the generated list as an array. You cannot modify an existing array using braces. You can only initialize a new array.


[ ] ARRAY[50] OF STRING array1
[ ] ARRAY[20][20][20] OF INTEGER array2
[-] testcase array_example ()
	[ ] // 39th element in one-dimensional array
	[ ] array1[39] = "alphabet soup"
	[ ] 
	[ ] // 5th element in 10th second-plane sub-array of 2nd
	[ ] // first-plane sub-array of 3-dimensional array 
	[ ] array2[2, 10, 5] = 99 
	[ ] 
	[ ] // these two statements access the same element
	[ ] array2[2, 4, 2] = 5 
	[ ] Print (array2[2][4][2]) //prints 5 
	[ ] 
	[ ] // initialize an array, starting with element 1 
	[ ] // and overwriting any elements previously set
	[-] array1 = {...}
		[ ] "foo"
		[ ] "bar" 
	[ ] // an alternative initialization 
	[ ] array1 = {"foo", "bar"}