DEV Community

loading...

Discussion on: How to Replace Loops using Recursion

Collapse
theowlsden profile image
Shaquil Maria

I have a question. Why would you use recursion instead of a for or while loop?

Collapse
rthefounding profile image
Randy Rivera Author • Edited

You definitely could but for this I used Recursion.

Collapse
wireless90 profile image
wireless90

Its easier to think recursively for harder problems. Like tower of hanoi or solving sudoku.

Collapse
cariehl profile image
Cooper Riehl

Notably, this varies from person to person. Some people think more effectively in terms of recursion, while others find it easier to use iteration. Neither one is inherently wrong, they just have pros and cons to be aware of.

Thread Thread
theowlsden profile image
Shaquil Maria

Aight aight, thanks for clarifying it for me. When I was starting with Java, we touched based on recursion and I use it from time to time, but I forgot if originally it had an effect on complexity and execution.