Why is there a warning | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
12th Feb 2023, 6:37 PM
Devin
Devin - avatar
1 Answer
+ 9
Devin because you have an expression that essentially its result is undefined. it's because you’re changing a variable more than once in it. return n * fibonacci(--n); you both multiplying n by a number (f(x)) and at the same time trying to decrement it (--n, result stroes in n, but there's another n also for multiplying n * f(x)). it has to decrement n and get the result of f(n), but also not decrement it because there is a multiplication by the current value of same variable n. so it's confusing to compiler. it doesn't matter to pass --n or n-1, both have same value for f(x) but in second case you haven't modify n twice. so just do: return n * fibonacci(n-1);
12th Feb 2023, 7:49 PM
Tina
Tina - avatar