Go to the first, previous, next, last section, table of contents.


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 section Scanning All Elements of an Array) with the split built-in function (see section Built-in Functions for String Manipulation). It works like this:

for (combined in array) {
  split(combined, separate, SUBSEP)
  ...
}

This sets combined to 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 a value in array[1, "foo"]; then an element with index "1\034foo" exists in array. (Recall that the default value of SUBSEP is 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.


Go to the first, previous, next, last section, table of contents.