This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Built-in Functions / Programming / Flow Control /


FilledSmallSquare For[start, test, incr, body] executes start, then repeatedly evaluates body and incr until test fails to give True.

FilledSmallSquare For evaluates its arguments in a non-standard way.

FilledSmallSquare For[start, test, incr] does the loop with a null body.

FilledSmallSquare The sequence of evaluation is test, body, incr. The For exits as soon as test fails.

FilledSmallSquare If Break[ ] is generated in the evaluation of body, the For loop exits.

FilledSmallSquare Continue[ ] exits the evaluation of body, and continues the loop by evaluating incr.

FilledSmallSquare Unless Return[expr] or Throw[expr] is generated, the final value returned by For is Null.

FilledSmallSquare Example: For[tot=0; i=0, i < 3, i++, tot += f[i]]. Note that the roles of semicolon and comma are reversed relative to the C programming language.

FilledSmallSquare See Section 2.6.9.

FilledSmallSquare See also: Do, While, Throw, NestWhile.

FilledSmallSquare New in Version 1.

Further Examples