NestWhileList
NestWhileList(f, expr, test)applies a function
frepeatedly on an expressionexpr, until applyingteston the result no longer yieldsTrue. It returns a list of all intermediate results.
NestWhileList(f, expr, test, m)supplies the last
mresults totest(default value:1). It returns a list of all intermediate results.
NestWhileList(f, expr, test, All)supplies all results gained so far to
test. It returns a list of all intermediate results.
NestWhileList[f, expr, test, m, max, n]applies
ftoexpruntiltestdoes not returnTrue. It returns a list of all intermediate results.testis a function that takes as its arguments the lastmresults.maxdenotes the maximum number of applications offandndenotes thatfshould be applied anotherntimes aftertesthas terminated the recursion. Ifnis a negative integer, the last-nelements will be dropped.
Examples
Divide by 2 until the result is no longer an integer:
>> NestWhileList(#/2&, 10000, IntegerQ){10000,5000,2500,1250,625,625/2}
>> NestWhileList(#+1 &, 1, True &, 1, 4, 5){1,2,3,4,5,6,7,8,9,10}Implementation status
- ✅ - full supported