Understanding Elixir loop

As many of you already know Elixir does not have loop. There are 2 main things to understand about this.

a) You need the same method signature to check the loop count

b) Your method need to be handling the real actions / tasks and not loop checker.

Let's see this in action. You have 2 runs methods and this has to match, otherwise elixir will complaint.

Next, the run method which implement loop check, just do what it suppose to do, check the counter.
Depending on true / false, you method "run" (without loop checking) is call. That's why you need to have implementation code like :timer.sleep in there.

defmodule FakeProcess do
def run(n) when n <= 1 do
IO.puts "serving as a final loop run"

def run(n) do
IO.puts n
run(n - 1)


Popular posts from this blog

Solving Sonarqube :- Project was never analyzed. A regular analysis is required before a branch analysis

spark - pyspark reading from excel files