Recursion explained

Illustrative flowchart of our recursive function

Our main function isn’t happy until our y value equals 0. To evaluate this condition it runs through a series of if statements that, if triggered, will modify the value of y, adding or subtracting accordingly. Our function is called over and over again until it is satisfied. Eventually our function calls itself again a last time, having reached the final value of x = 0 and y = 0, it can finally rest.



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