[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.13 FOR

In its argumentless form, repeatedly executes the remainder of the line on which FOR was encountered until a QUIT, GOTO, or end-of-line is encountered, provided the optional postcondition evaluates to true or is omitted.

Syntax

FOR[:postcondition]

Non-Standard Behavior

FreeM allows a postcondition on FOR. Much like postconditions on ELSE and IF, this is explicitly forbidden in the standard. Although there is an argument to be made that this feature of FreeM might be confusing, in the author’s opinion, this use of postconditions is a much cleaner and more precise construct than using IF followed by FOR.

If you wish to ensure portability of your FreeM code to other, more rigid M implementations, this use of postconditions should quite obviously be avoided. However, you earn FreeM coolness points for using this feature, which have no value and may not be redeemed for anything at all.

In its sentinel form, repeatedly executes the remainder of the line and sets a sentinel variable on each iteration, provided the optional postcondition evaluates to true or is omitted.

On the first iteration of the loop, glvn will be set to initalizer-expression. On each subsequent iteration, glvn will be incremented by increment-expression, and the loop will terminate when glvn meets or exceeds the value of max-expression.

Syntax

FOR[:postcondition] glvn=initializer-expression:increment-expression:max-expression

Example

USER> FOR I=1:1:10 WRITE I,!

1
2
3
4
5
6
7
8
9
10

USER> FOR I=2:2:10 WRITE I,!

2
4
6
8
10

In its explicit parameter form, a variable is set to each of a series of explicit values, once per iteration, provided the optional postcondition evaluates to true or is omitted. The loop terminates when no more values are available.

Syntax

FOR[:postcondition] glvn=expr1[,..exprN]

Example

USER> FOR I=60,"FOO",-3,"George",1450,$HOROLOG WRITE I,!

60
FOO
-3
George
1450
66106,52388

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on January 3, 2022 using texi2html 5.0.