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 / New in Version 4.x / Programming /

NestWhile

FilledSmallSquare NestWhile[f, expr, test] starts with expr, then repeatedly applies f until applying test to the result no longer yields True.

FilledSmallSquare NestWhile[f, expr, test, m] supplies the most recent m results as arguments for test at each step.

FilledSmallSquare NestWhile[f, expr, test, All] supplies all results so far as arguments for test at each step.

FilledSmallSquare NestWhile[f, expr, test, m, max] applies f at most max times.

FilledSmallSquare NestWhile[f, expr, test, m, max, n] applies f an extra n times.

FilledSmallSquare NestWhile[f, expr, test, m, max, -n] returns the result found when f had been applied n fewer times.

FilledSmallSquare NestWhile[f, expr, test] returns the first expression f[f[... f[expr]... ]] to which applying test does not yield True.

FilledSmallSquare If test[expr] does not yield True, NestWhile[f, expr, test] returns expr.

FilledSmallSquare NestWhile[f, expr, test, m] at each step evaluates test[, , ... , ]. It does not put the results in a list.

FilledSmallSquare The are given in the order they are generated, with the most recent coming last.

FilledSmallSquare NestWhile[f, expr, test, m] does not start applying test until at least m results have been generated.

FilledSmallSquare NestWhile[f, expr, test, mmin, m] does not start applying test until at least mmin results have been generated. At each step it then supplies as arguments to test as many recent results as possible, up to a maximum of m.

FilledSmallSquare NestWhile[f, expr, test, m] is equivalent to NestWhile[f, expr, test, m, m].

FilledSmallSquare NestWhile[f, expr, UnsameQ, 2] is equivalent to FixedPoint[f, expr].

FilledSmallSquare NestWhile[f, expr, test, All] is equivalent to NestWhile[f, expr, test, 1, Infinity].

FilledSmallSquare NestWhile[f, expr, UnsameQ, All] goes on applying f until the same result first appears more than once.

FilledSmallSquare NestWhile[f, expr, test, m, max, n] applies f an additional n times after test fails, or max applications have already been performed.

FilledSmallSquare NestWhile[f, expr, test, m, max, -n] is equivalent to Part[NestWhileList[f, expr, test, m, max], -n-1].

FilledSmallSquare NestWhile[f, expr, test, m, Infinity, -1] returns, if possible, the last expression in the sequence expr, f[expr], f[f[expr]], ... for which test yields True.

FilledSmallSquare See Section 2.2.2.

FilledSmallSquare See also: NestWhileList, FixedPoint, Nest, While.

FilledSmallSquare New in Version 4.

Further Examples