I'm reviewing for an exam in Scala, and trying to figure out this quiz question that I missed. I understand tail recursion as "last call is itself", but I'm confused about the difference between some of these code snippets. Why is this considered tail recursive,
def f(x: Int): Int = {
if (x % 2 == 0) {1}
else {f(x + 1)}
but this, is not?
def f(x: Int): Int = {
if (x % 2 == 0) {1}
else {1 + f(x + 1)}
What exactly does adding 1 to the function do that restricts it from being tail recursive? I'm sorry if this is a silly question, I don't see the affect the number has and want to solidify my understanding. Any other pointers at fully being able to identify tail recursion would be awesome too!