f[a_, b_] := {a, b};
Block[
{
n := 1,
l := {{x, y}}
},
Do[
Print[n];
l := f[{1/n, 1/(n + 1)}, l];
n := n + 1;
Print[n],
5
]
]
which produces
1
and
$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of n+1. >>
Actually I want to do more complicated things in f with the elements {1,1/2), {1/2,1/3), {1/3,1/4}… and so on. What i dont undestand is why all of a sudden this one here complains about recursion.
I am using 10.2 on PC / OS/X and it happens in a fresh notebook???
OK. I found it myself. replacing := with = did the trick. Lesson learned: With Mathematica you have to read evey word of the documentation and think twice about it. Then you understand it halfways. := does lazy evaluation and thus n had no value when computing n+1. Using the = operator, assignment was immediate and everyting went smoothly. To my excuse i can say that Pascal was my first language, where := is the regular assignment operator.