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 ↗
In[n:−0,While(n<5,n:−n+1),n]\bigl\lbrack n\coloneq0, \mathrm{While}(n\lt5, n\coloneq n+1), n\bigr\rbrackOut[0,5]\bigl\lbrack0, 5\bigr\rbrack
About
Examples1
CrosswalkWolfram Language

See also: Do, NestWhile