> For the complete documentation index, see [llms.txt](https://muradkarakas.gitbook.io/sodium_documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://muradkarakas.gitbook.io/sodium_documentation/language-reference/lexical-elements/functions/recursive-functions.md).

# Recursive Functions

Recursive Functions is supported.

You can write a function that is recursive (a function that calls itself). Here is an example that computes the factorial of an integer:

```
int factorial(int x) {
    if (x < 1) then
        return 1;
    else
        return (x * factorial (x - 1));
    end if;
};
```

Be careful that you do not write a function that is infinitely recursive. In the above example, once x is 1, the recursion stops. However, in the following example, the recursion does not stop until the program is interrupted or runs out of memory:

```
int watermelon (int x) {
  return watermelon(x);
};
```

Functions can also be indirectly recursive, of course.
