Recursion question

I know this is solved but here are some useful resources regarding recursion:

https://developer.roblox.com/en-us/articles/Recursion

To try an explain it myself, when the conditional check is performed “n <= 1” if when evaluated a Boolean value of true results (which would indicate n is equal to or less than 1 a number of 1 value is returned to the point at which the function was called. Otherwise if n is greater than 1 a return statement is executed which multiplies the current value of n with the value returned by calling the defined function named “factorial” (this is where the recursion occurs) and passing the current value of n with 1 subtracted from it as an argument to the function. Whenever a function is called its returned value(s) are returned to the exact point at which the function was called, so here when the recursion ends the final value is returned and subsequently passed as an argument to the print call, when the recursion is ongoing those returned values are being returned at the end of the return statement of the function named “factorial”.

1 Like