Go backward to Multi-dimensional.
Go up to Arrays.
Scanning Multi-dimensional Arrays
=================================
There is no special `for' statement for scanning a
"multi-dimensional" array; there cannot be one, because in truth there
are no multi-dimensional arrays or elements; there is only a
multi-dimensional *way of accessing* an array.
However, if your program has an array that is always accessed as
multi-dimensional, you can get the effect of scanning it by combining
the scanning `for' statement (see Scanning all Elements of an Array: Scanning an Array.) with the `split' built-in function (*note Built-in
Functions for String Manipulation: String Functions.). It works like
this:
for (combined in ARRAY) {
split(combined, separate, SUBSEP)
...
}
This finds each concatenated, combined index in the array, and splits it
into the individual indices by breaking it apart where the value of
`SUBSEP' appears. The split-out indices become the elements of the
array `separate'.
Thus, suppose you have previously stored in `ARRAY[1, "foo"]'; then
an element with index `"1\034foo"' exists in ARRAY. (Recall that the
default value of `SUBSEP' contains the character with code 034.)
Sooner or later the `for' statement will find that index and do an
iteration with `combined' set to `"1\034foo"'. Then the `split'
function is called as follows:
split("1\034foo", separate, "\034")
The result of this is to set `separate[1]' to 1 and `separate[2]' to
`"foo"'. Presto, the original sequence of separate indices has been
recovered.