What is the difference between loops and recursion and which one is more preferred for solving a problem?
Asked
Active
Viewed 142 times
-3
-
1Did you try searching on SO for an answer? There are many threads on this (broad) question, e.g [Efficiency: recursion vs loop](https://stackoverflow.com/questions/9386375/efficiency-recursion-vs-loop) or [Recursion vs loops](https://stackoverflow.com/questions/660337/recursion-vs-loops) – Jeppe May 28 '19 at 11:48
1 Answers
0
Loop is repeated execution of a block of code until the given condition is false.Loop has a linear flow from initial condition to terminating condition.
On the other hand recursion is a method/function being called by itself. Recursion takes place creating stack of task ie, each calling function returns to its caller function after execution.
Loop and recursion aren't exactly alternatives to have preferences, they are used for different type of tasks.

Yasir
- 332
- 2
- 9
-
nitpick: loops don't require a terminating condition and recursion doesn't require a stack – Mulan May 28 '19 at 14:12