We know how to implement loops in Object-Oriented style: Using Mutable Temporary variables, update the variable value and use Loop constructs. It is very tedious and unsafe approach. It is not Thread-Safe. Object-Oriented style uses the following constructs to implement Loops:
- Loop Constructs
- Mutability
- Side Effects
We can implement same Loops differently in Functional way. It is Thread-Safe. We can use the following two techniques to implement the loops in functional style:
- Recursion
- Tail-Recursion
- Immutability
- No Side-Effects