NestWhile

NestWhile[f, expr, test, m, max, n] applies f to expr until test does not return True. test is a function that takes as its argument the last m results. max denotes the maximum number of applications of f and n denotes that f should be applied another n times after test has terminated the recursion.

Attributes[NestWhile] := {Protected}

Simple examples

In[1]:= NestWhile[Function[Slot[1]^2], 2, Function[(Slot[1]) < (256)]]
Out[1]= 256
In[2]:= NestWhile[Function[Slot[1] + 1], 1, Function[((Slot[1] + Slot[4])) < (10)], 4]
Out[2]= 7
In[3]:= NestWhile[Function[Slot[1] + 1], 1, Function[True], 1, 4]
Out[3]= 5
In[4]:= NestWhile[Function[Slot[1] + 1], 1, Function[True], 1, 4, 5]
Out[4]= 10