# To understand recursion, you must understand recursion

A recursive algorithm is one that calls itself.

In order to not get stuck in an infinite loop, it must return a call to itself with continuously changing inputs that will approach a base case or terminating case. If the inputs equal that case, the algorithm will return a set value and stop calling itself. Recursive algorithms make use of the call stack because each new call feeds the previous call. Each step on the way to the solution contains a piece of the whole. Recursion is an implementation of self-similarity and has many applications in mathematics, computer and natural sciences.

This function uses recursion to generate the nth number in the fibonacci sequence. The fibonacci sequence is a mathematical sequence where each number is the sum of the two previous numbers in the sequence. It begins with 1 and 1 as the first two numbers in the sequence, base conditions for when there are not two previous numbers to add together. The third number is then two(1+1), the fourth three(2+1), the fifth five(3+2). A recursive algorithm populates the call stack with calls to itself with a lower value for num, and those calls return back up the chain when it reaches the beginning of the sequence when num === 1 and num ===0. The Fibonacci sequence is related to the golden ratio, or phi, an important ratio in mathematics and nature. As n approaches infinity, the ratio between the nth and the (n-1)th number in the sequence approaches phi, which is approximately 1.618. Phi is often visually represented by the golden spiral, itself a recursive image, containing itself infinitely.