Write while loop equivalent in elixir

Your code example here implies mutation, so “real life” may look a little differently in a functional language. For example if you want to generate a list of new names until they stop existing you can do something like:

Stream.repeatedly(&generate_name/0) |> Enum.take_while(&exists?/1)

There are a hundred little variations on that you can do, combining various stream generators like repeatedly/1, unfold/1 and so forth with Enum.take* variants.

If those patterns aren’t a good fit, manual recursion is always a simple function a way.