+ 1
Return values in recursion function
E.g. in the factorial function which lowers x each time it calls itself. Does "return" by default add up all previous return values in a recursive function? Otherwise I don´t get how factorial(5) returns 120. Also, "if x=1 return 1". So why does it not return 1 in the very last iteration?
1 Respuesta
0
In each iteration return statement adds the previous iteration values to the current value till the last iteration then in the last iteration it will return the final calculated value