HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to eliminate for/if/while from algorithms when it's possible

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
whilealgorithmspossibleeliminateforhowfromwhen

Problem

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).

Solution

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.

Context

StackExchange Computer Science Q#11618, answer score: 2

Revisions (0)

No revisions yet.