+ 2
Whats the difference between recursion and loops? Is there any speed difference between them or not ??
4 odpowiedzi
+ 3
Yes, absolutely...that's why you still can use it. But the risk remains because every time you call a rec function it occupies a newer part of the stack, while in loops at every iteration data is overloaded.
It depends on how you write your code, you just have to be careful when using rec.
+ 2
But sir Stack overflow can be prevented using conditionals
0
Generally it's safer using loops...recursion can generate stack-overflow.
Sometimes you can use recursion to make the code easier to read and for problems that can be broken into same smaller problems but you have to make sure that stack-overflow won't occur.
0
Recursion means calling a function to itself.
Loop means executing the code certain amount of time. ( Here we already knows how many time the code get executed)