Recursion We have seen that repetition can be achieved by writing loops, such as for loops and while loops. Another way to achieve repetition is through recursion, which occurs when a function calls itself. We have seen examples of methods calling other methods, so it should come as no surprise that most modern programming languages, including Java, allow a method to call itself. In this section, we will see why this capability provides an elegant and powerful alternative for performing repetitive tasks. The Factorial function To illustrate recursion, let us begin with a simple example of computing the value of the factorial function. The factorial of a positive integer n, denoted n!, is defined as the product of the integers from 1 to n. If n = 0, then n! is defined as 1 by convention. More formally, for any integer n ≥ 0