| 318 | | === `$for` |
| | 318 | === Domain iteration statement: `$for` |
| | 319 | |
| | 320 | A domain statement has the form |
| | 321 | |
| | 322 | `$for` `(``int` ''i1''`,` ...`,` ''in'' `:` ''dom''`)` ''S'' |
| | 323 | |
| | 324 | where ''i1'', . . . , ''in'' are ''n'' identifiers, ''dom'' is an expression of type `$domain(`''n''`)`, and ''S'' is a statement. |
| | 325 | The identifiers declare ''n'' variables of integer type. |
| | 326 | Control iterates over the values of the domain, assigning the integer variables the components of the current tuple in the domain at the start of each iteration. |
| | 327 | The scope of the variables extends to the end of ''S''. |
| | 328 | The iterations takes place in the order specified by the domain, e.g., dictionary order for a Caretesian domain. |
| | 329 | Note that if a range expression can be used as ''dom'' here, it will be automatically converted to a one-dimensional domain. |
| | 330 | For example, |
| | 331 | {{{ |
| | 332 | $for (int i : 0 .. 10) S |
| | 333 | }}} |
| | 334 | is equivalent to |
| | 335 | {{{ |
| | 336 | $for (int i: ($domain(1)){0 .. 10}) S |
| | 337 | }}} |
| | 338 | |
| | 339 | There is a also a parallel version of this construct, `$parfor`. |