There is no return keyword so code must be organized to return early. The follow example shows how to organize code to return early in Elixir.

For example, the early return in ruby:

def hello
  if some_condition
     return "Goodbye"
  end
  do_this()
  do_something()
end

Could look like this in Elixir:

def hello do
  if some_condition do
    "Goodbye"
  else
     do_this()
     do_something()
  end
end

Case and cond can also be used to return different values based on a condition.

See Also: