0

What is Recursion?

Can someone please explain me what recursion is in ruby? I have completed the course but still can’t understand what recursion is.

28th Dec 2017, 6:52 AM
Arfaan
Arfaan - avatar
4 odpowiedzi
+ 4
Recursion- When a Function calls itself, that is known as recursion. For a recursive algorithm to terminate you always need a base case and you should make sure that you get closer to that base case in each recursive call, ensuring that you will achieve base case. example: def sum_array if the array is empty return 0 else head of array + sum_array(tail of array) end end (factorials, Fibonacci sequence are other simple examples to use recursion)
28th Dec 2017, 6:55 AM
Qwqwq Rt
Qwqwq Rt - avatar
+ 4
recursion is when a function calls itself repeatedly. function hey(){ console.log("a"); hey()} b is consoled forever because when the function is called,it calls itself
28th Dec 2017, 7:20 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 2
Thank you Rame and Brains. I think I kinda get it now. And GAWEN STEASY, why did you link me to the ruby tutorial? I completed it already and I didn’t understand what the tutorial said about recursion so I asked here.
28th Dec 2017, 12:37 PM
Arfaan
Arfaan - avatar