Next: , Previous: , Up: Built-in functions   [Contents][Index]


7.2.3.13 $DO: Macro do loop

$DO(macro,imin,imax[,di]){...}’ repetitively defines macro as would the FORTRAN statement ‘do macro = imin,imax,di’. For example,

$DO(I,0,2)
  {
  a[I] = I;
  }

generates the three statements

  a[0] = 0;
  a[1] = 1;
  a[2] = 2;

In general, the macro name used as loop counter should not be explicitly defined as a macro prior to the $DO. If it is not, it will remain undefined after the end of the iteration.

Instead of the delimiting braces, parentheses may be used. These may be useful to help FWEAVE format certain constructions correctly.

Nested delimiters are handled correctly. The delimiters are required even if only a single statement is to expanded.

$DO is implemented in terms of a command $UNROLL. However, if one says something like ‘$DUMPDEF($UNROLL(0,5,1))’, FWEB will respond that $UNROLL is not an FWEB macro. Rather, $UNROLL is processed like expandable commands in RATFOR such as while. This implies that it cannot be redefined as ordinary macros or built-in functions can be.