r/computerscience • u/ShadowGuyinRealLife • May 22 '25
Discussion Why Are Recursive Functions Used?
Why are recursive functions sometimes used? If you want to do something multiple times, wouldn't a "while" loop in C and it's equivalent in other languages be enough? I am not talking about nested data structures like linked lists where each node has data and a pointed to another node, but a function which calls itself.
106
Upvotes
View all comments
Show parent comment
3
u/xeow May 22 '25
Can you give a concrete example of that? I always thought that compound financial values were calculated not using iteration or recursion but mathematically using exp() and log() to obtain precise values down to microsecond granularity. For example, compound interest is never calculated yearly or even weekly or daily...it's calculated instantaneously for any arbitrary given duration using fractional exponentiation.