Skip to content

While ​

Evaluates an expression repeatedly while a test stays true.

Wolfram LanguageWhile
While(test)Re-evaluates testtest until it reads other than TrueTrue.
While(test, body)Evaluates bodybody each time testtest (re-evaluated first) reads TrueTrue; stops as soon as it doesn't.
Typed signatures
TypePackageApplies
(any, any?) -> anycombinatoricsalways

Domain: Collections

Details
  • Always returns NothingNothing, like Do.
  • Capped at 4096 iterations, past which the loop simply stops — Wolfram's own default cap, $IterationLimit, is much larger and configurable; this one is fixed.

Examples

Basic #

count up to a limit

live ↗
InAssign(n,0);While(n<5,n:−n+1);n\mathrm{Assign}(n, 0); \mathrm{While}(n\lt5, n\coloneq n+1); nOut55
About
Examples1
CrosswalkWolfram Language

See also: Do, NestWhile