Recursion, iteration, and …? [closed]
https://softwareengineering.stackexchange.com/questions/286438
-
09-10-2020 - |
Question
Here are three common code structures that apply a function multiple times:
foo(x) {
if basecase(x) return k else return foo(g(x))
}
uses recursion.
for i in 0..10 {
n *= bar(i)
}
uses iteration.
baz(baz(baz(baz(quux))))
uses...?
In mathematics it'd be considered iteration, but mathematics doesn't generally concern itself with for
and while
loops, which are what people associate with the term in programming. How do programmers tersely and unambiguously refer to the third construct?
Solution
The term you're looking is for is function composition, although I'm not sure if there's a more specific term for the special case of a function composed with itself.
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange