Is there any way to find out how to replace for/if for elementary recursive algorithms? I know that primitive recursive functions cannot basically eliminate "for", but for elementary recursive functions, there must be a way to convert the program into ones that do not have for/if/while and so on (which is elementary recursive).
1 Answer
$\begingroup$
$\endgroup$
2
For/if/while are the main blocks that will check for a condition. Since a recursive function will keep recurring until a condition is met, you will at least need an if statement to tell the function when to return. Otherwise, you will essentially be stuck in an infinite loop.
-
$\begingroup$ Welcome to Computer Science Stack Exchange. Please read cs.stackexchange.com/tour, if you have not yet done so. $\endgroup$– babouCommented Aug 10, 2015 at 16:05
-
1$\begingroup$ This is pretty much true. At least if you extend 'if statement' to any kind of branching this is true. $\endgroup$– JakeCommented Aug 10, 2015 at 16:36
for
andwhile
are very similar. So isrepeat
. Do you keeprepeat
? $\endgroup$