This commit is contained in:
Miloslav Ciz 2022-04-29 18:26:15 +02:00
parent d59533548b
commit 805062a922
12 changed files with 75 additions and 30 deletions

View file

@ -1,5 +1,7 @@
# Recursion
*See [recursion](recursion.md).*
In general recursion is a situation in which a [definition](definition.md) refers to itself; for example the definition of a human's ancestor as "the human's parents and the ancestors of his parents" ([fractals](fractal.md) are also very nice example of what a simple recursive definition can achieve). In programming recursion takes on a meaning of a **function that calls itself**; this is the meaning we'll suppose in this article, unless noted otherwise.
We divide recursion to a **direct** and **indirect** one. In direct recursion the function calls itself directly, in indirect function *A* calls a function `B` which ends up (even possibly by calling some more functions) calling *A* again. Indirect recursion is tricky because it may appear by mistake and cause a [bug](bug.md) (which is nevertheless easily noticed as the program will mostly run out of memory and crash).