cond

cond can be seen as a multi-way if statement, where the first truthy condition will run its associated code. This may substitute chains of if ... else if blocks. Let's see this with an example on IEx:

iex> x = 55iex> cond do...>   x * x == 9 -> "x was 3"...>   x * x == 16 -> "x was 4"...>   x * x == 25 -> "x was 5"...>   true -> "none of the above matched"...> end"x was 5" 

true in a condition will serve as a default condition, which will run when no other clause matches.

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.