0
Recursion
can any one explain what is the difference between recursion & loop?
2 odpowiedzi
0
The loop is repeated a fixed number of times until a condition is met. Recursion is when a procedure calls itself with different parameters.
0
In many cases a loop and recursion can accomplish the same task, but the loop will tend to go faster. Unfortunately, the way that most people teach recursion (factorials) is not that great/intuitive and a loop will actually work faster because it won't have to store so many function calls in memory.
Bottom line, they are fairly interchangeable for 99% of circumstances. And when they are interchangeable, it would probably be most efficient and understandable to use a loop.