tiltboi1

tiltboi1 t1_j2f2c5o wrote

“return” essentially means that the function is done, and provides a way of giving an output. Usually a function is “called” by another function which needs its results, so the return keyword is saying we are done and ready to go return to the calling function.

The reason why we use a special keyword has to do with how functions are actually called. Each time a function is called, it’s parameters, local variables, etc are saved to RAM in a block called a stack frame. But during the computation of this function, you may need to call another function. The parameters and local variables are saved into another stack frame next to it. The return keyword initiates the procedure of deleting the current stack frame, and moving back to the older one.

3