To Find Out What Recursion Does, Just Find Out What Recursion Is Doing.

Recursion represented in the form of squares.
  • A recursive function is a function that calls itself.
  • This example is a recursive function that calculates the power of x to the yth
  • x = a number
  • y = the exponent (how many copies of x to multiply together)
Step by step look at a simple recursive function!
  1. X and Y are both assigned the value of 2, and passed in as arguments to the _pow_recursion() function.
  2. The arguments are evaluated to see if it meets the **Base Case, which will be if y is equal to zero. Since y is 2 and not zero, we will continue on to step
  3. Check to see if y is a negative number. If yes, skip step 5. If no, skip step 4.
  4. Evaluate the recursive case by adding it to the stack, then repeating the process over from step 1!
  5. Evaluate the recursive case by adding it to the stack, then repeating the process over from step 1!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store