check out this Scala-code:
def rec(n: Int) {
if (n > 1) {
val d = n / 2
rec(d)
// if (d > 1) // abort loop
rec(n/d)
}
}
This code will result in an endless loop. Owing to tail recursive optimization I don't get a StackOverflowError.
Decompiled with jad I got this Java-code:
public void rec(int n)
{
int d;
for(; n > 1; n /= d)
{
int i = n;
d = i / 2;
rec(d);
}
}
In the last line of the loop the method calls itself therefore I don't understand the tail call position. Anyone who can explain this?