Previous: , Up: Operators   [Index]


6.3.4 Array Subscript

INTERCAL-72 C-INTERCAL CLC-INTERCAL J-INTERCAL
yes version 0.7+ all versions all versions

In order to access the elements of an array, either to read or write the array, it is necessary to use the array subscript operator SUB. Note that an array element is not a variable, so it is not accepted as an acceptable argument to statements like IGNORE; however, it can be assigned to.

The syntax for an array element is the array, followed by the keyword SUB, followed by an expression for the element number in the array. In the case of a multidimensional array, more than one expression is given after the keyword SUB to give the location of the element in each of the array’s dimensions. The first element in an array or array dimension is numbered 1.

For instance, this is a legal (but not particularly useful) INTERCAL program with no syntax errors that shows some of the syntaxes possible with array subscripting:

PLEASE ,1 <- #2
DO .1 <- #2
DO ,1 SUB .1 <- #1
DO ,1 SUB #1 <- ,1 SUB #2
PLEASE ;1 <- #2 BY #2
DO ;1 SUB #1 #2 <- ,1 SUB ,1 SUB .1
DO READ OUT ;1SUB#1.1
DO GIVE UP

Grouping can get complicated when nested array subscripting is used, particularly with multiple subscripts. It is the programmer’s job to write an unambiguous statement, and also obey the extra grouping rules that apply to array subscripts; see Grouping Rules.