Recursionis a major tool in the toolbox of the software engineer.
It can allow to describe a problem from a different perspective.
In the context ofFunctional Programmingthis is also a major trick to avoid usingmutablevariables.
This is a very basic example to be able to understand the concept of recursion fully. In the future, we will see more complex application ofrecursion.
To build a successful recursion, you need several things:
StackOverflowError.loopfunction is called inside of itself.loopis called, it is called with modified arguments.acc.accequals to0.The most famous example of recursion in books are alwaysfactorialorFibonacci. I would love to see your implementation, feel free to submit a Scastie link in the comment section or on Discord.