DEV Community

Discussion on: Intro to Recursion in JS

Collapse
 
nestedsoftware profile image
Nested Software • Edited

The Ackermann function is indeed not "primitive recursive." However, it is computable, and therefore can be computed with loops. A while loop would work for example.

If you only have a for item in items type of loop where items cannot be changed inside the loop, that would not be good enough to compute the Ackermann function though.

It's easy to get confused with this stuff, but anything that you can implement with a computer program can be done without recursion. You can think of it this way: Hardware doesn't support recursion in the actual electronics (at least I don't think so), yet code in any programming language can be compiled down to machine language that's executed by the hardware.