# Can I make a Function Call Itself?

**URL:** https://discourse.julialang.org/t/can-i-make-a-function-call-itself/64067
**Category:** New to Julia
**Tags:** question
**Created:** [July 5, 2021, 9:41am UTC](https://discourse.julialang.org/t/can-i-make-a-function-call-itself/64067 "2021-07-05T09:41:21Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [July 5, 2021, 11:19am UTC](https://discourse.julialang.org/t/can-i-make-a-function-call-itself/64067/4 "2021-07-05T11:19:31Z")

</div>

This is called [recursion](https://en.wikipedia.org/wiki/Recursion_(computer_science)), an important technique in computer science. Note that each call allocates on the stack, so if you go too deep you will get a [stack overflow](https://en.wikipedia.org/wiki/Stack_overflow) (which gave its name to a famous website).

```julia
julia> counter = 0;

julia> function f()
           global counter += 1
           f()
       end;

julia> f()
ERROR: StackOverflowError:
Stacktrace:
 [1] f()
   @ Main ./REPL[12]:2
 [2] f() (repeats 79980 times)
   @ Main ./REPL[12]:3

julia> counter
130830

```

So `f` was able to call itself recursively 130830 times before the stack grew too big.

---

_[View the full topic](https://discourse.julialang.org/t/can-i-make-a-function-call-itself/64067)._
