Please enable JavaScript to view this site.

A-Shell Reference

Although you can use a regular FOR…NEXT loop to effectively iterate through the rows (and for gridmaps with numeric columns, the columns as well), keep in mind that unlike a regular two dimension array, there is no guarantee that the rows start at 1.  And there is no way to use a FOR…NEXT loop to iterate through alphanumeric columns. You can use the .MINROW() and .MAXROW() functions to obtain the range of row numbers, and in the case of numeric columns, the .MINCOL() and .MAXCOL() functions to obtain the range of column numbers for each row.

Alternatively, you can use a FOREACH $$i loop to iterate through the gridmap as you would through an ordered map, except that it will iterate through the columns of each row before starting on the next row.  Use the .KEY() function to determine the row and column position of the iterator. For example, to iterate through an entire gridmap, listing the row, column and cell values:

foreach $$i in $map()

    ? "Row "; .key($$i,1); ", Col "; .key($$i,2); "-->"; $$i

next $$i

 

As with iteration through an ordered map, you can limit the range of iteration by specifying a starting starting (or a starting and ending) key, although in this case the key only applies to the row numbers. The above example could be limited to just rows 5 through 10 as follows:

foreach $$i in $map(5,10)        ! iterate through rows 5-10

 

To iterate through the rows on a single column, you would have to use a FOR..NEXT loop as follows:

for row = .minrow($map) to .maxrow(.map)

    ? row, $map(row,col)     ! (col numeric or alphanumeric, depending on gridmap type)

next row

 

Warning: when iterating through numeric rows and columns, although negative values come before positive values in the iteration (as expected), the negative values in the iteration will be ordered according to their absolute value. For example, if the grid contains a range of row numbers from negative two to positive two, they will iterate in the sequence:  -1, -2, 0, 1, 2 (rather than -2, -1, 0, 1, 2). This is a consequence of the way the keys are stored as strings, and also because negative row values are mainly intended to be used for special meta data.

Writeable Iterators

As with ordered map iterators, you can write to the value of a gridmap iterator, but deleting or modifying a key will render the iterator unpredictable.