This repeatedly applies divide2 until the result is no longer an even number:
This repeatedly applies newton3, stopping when two successive results are no longer considered unequal, just as in FixedPointList:
This goes on until the first time a result that has been seen before reappears:
Operations such as Nest take a function f of one argument, and apply it repeatedly. At each step, they use the result of the previous step as the new argument of f.
It is important to generalize this notion to functions of two arguments. You can again apply the function repeatedly, but now each result you get supplies only one of the new arguments you need. A convenient approach is to get the other argument at each step from the successive elements of alist.
Fold gives the last element of the list produced by FoldList:
This gives a list of cumulative sums:
Using Fold and FoldList you can write many elegant and efficient programs in the Wolfram Language. In some cases, you may find it helpful to think of Fold and FoldList as producing a simple nesting of a family of functions indexed by their second argument.
This defines a function nextdigit:
This is now like the built‐in function FromDigits: