Unlike in imperative languages, functional programming languages (including Elixir) achieve looping through recursion. Why? To explain that, let's consider C:
Say, we want to print the message "hello" five times. How do we do that?
for(i = 0; i < 5; i++) {
  sum = sum + i;
}Say, we want to print the message "hello" five times. How do we do that?
defmodule Recursion do
  def print_hello(n) when n <= 1 do
    IO.puts "hello"
  end
  def print_hello(n) do
    IO.puts "hello"
    print_hello(n - 1)
  end
end
Recursion.print_hello("Hello!", 3)
# Hello!
# Hello!
# Hello!
In this case, when n = 3 and n = 2, the second clause will be executed. When n = 1, the first clause will get executed. 
Read more:
