Content deleted Content added
Citation bot (talk | contribs) Altered title. | Use this bot. Report bugs. | Suggested by Dominic3203 | Category:Computability theory | #UCB_Category 50/102 |
Added a section (Infinite Recursion) |
||
Line 857:
| publisher = Pearson | ___location = Hoboken
}}</ref>
== Infinite recursion ==
{{See also|Infinite loop#Infinite recursion}}
A common mistake among programmers is not providing a way to exit a recursive function, letting it run infinitely. This is called ''infinite recursion''. If you don't provide a way to exit the function, it will go on making recursive calls forever and the program will never terminate. This is a very bad idea, since it will eat up the [[Stack (abstract data type)|stack]]. In most programming environments, a program with an infinite recursion will not really run forever. Eventually, something will break and the program will report an error.<ref>{{Cite web |title=4.8. Infinite Recursion |url=https://runestone.academy/ns/books/published/thinkcpp/Chapter4/InfiniteRecursion.html}}</ref>
Below is a Java code that would use infinite recursion:<syntaxhighlight lang="java" line="1">public class InfiniteRecursion {
static void recursive() { // Recursive Function with no way out
recursive();
}
public static void main(String[] args) {
recursive(); // Executes the recursive function upon runtime
}
}</syntaxhighlight>Running this code will give you a [[stack overflow]] error.
==See also==
|