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 While[test, body] evaluates test, then body, repetitively, until test first fails to give True.

FilledSmallSquare While[test] does the loop with a null body.

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

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

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

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

FilledSmallSquare See Section 2.6.9.

FilledSmallSquare See also: Do, For, NestWhile, Nest, Fold, Select, Throw.

FilledSmallSquare New in Version 1.

Further Examples