25,161
edits
Changes
no edit summary
It is interesting to convert this recursive procedure to an iterative (non-recursive) form by a sequence of mechanical transformations, and to apply simple optimizations which preserve program correctness. The resulting procedure is surprisingly simple, but not as easy to prove correct as the recursive form.
Generally every Recursive Function can also be converted into an Iterative Search by means of replacing the function calls by jumps ([[C#Goto|goto]], break, continue) within the function itself <ref>[http://c-faq.com/style/stylewars.html comp.lang.c FAQ list · Question 17.10]</ref>. The result is usually more efficient as the calling of a function is slower than just jumps within the function. The main downside however is the increased complexity and decreased readability <ref>[https://en.wikipedia.org/wiki/Spaghetti_code Spaghetti code from Wikipedia]</ref>.