# Write while loop equivalent in elixir

**URL:** <https://forum.elixirforum.com/t/write-while-loop-equivalent-in-elixir/15880>\
**Category:** Questions\
**Tags:** while, loop\
**Created:** [August 16, 2018, 11:03am UTC](https://forum.elixirforum.com/t/write-while-loop-equivalent-in-elixir/15880 "2018-08-16T11:03:27Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![sribe](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sribe](https://forum.elixirforum.com/u/sribe)\
**Post date:** [April 4, 2020, 1:32pm UTC](https://forum.elixirforum.com/t/write-while-loop-equivalent-in-elixir/15880/27 "2020-04-04T13:32:42Z")

</div>

> [@silverdr](#):
>
> And if I wanted to limit the depth?

Well if you want to limit the depth, you can always pass along a depth counter. But you probably won’t want to limit depth–other than to make sure that the recursive call is the last thing your function does, so that tail call optimization can limit the actual stack depth to 1.

---

_[View the full topic](https://forum.elixirforum.com/t/write-while-loop-equivalent-in-elixir/15880)._
