spec

Software for Diffraction

2.3.17.3. - For Statement



The for statement comes in two forms. The first is
for ( expression1 ; expression2 ; expression3 ) statement
The flow expressed in this statement can be thought of as
expression1
while ( expression2 ) {
      statement
      expression3
}
Any of the expressions can be missing. A missing expression2 is equivalent to
while ( 1 )
The second form of the for statement is used with associative arrays. The construction
for ( identifier in assoc-array ) statement
will run through each element of the associative array assoc_array assigning to identifier the string value of the index of each element. The elements will be sorted using a "natural sort" ." "Natural sort" means that consecutive digits are treated as a single character and sorted according to their value as a group, such that a10 will come after *a9, contrary to the order with strict lexicographical sorting.

For two-dimensional associative arrays, the construction
for ( identifier in assoc-array[expr] ) statement
will step through each element of assoc-array having expr has the first index.