Branching with if and else in Elixir is straightforward.
Note that in Elixir, you don’t need parentheses around conditions, but the do and end keywords are required to define the block.
To run the program:
In Elixir, there’s no direct equivalent to Go’s ability to declare a variable in an if statement. Instead, we typically assign the variable before the conditional structure.
Also, Elixir doesn’t have a direct else if construct. For multiple conditions, it’s common to use cond as shown in the last example. Alternatively, you can nest if statements or use pattern matching with case.
Elixir also provides a ternary-like operator with the if macro:
This can be useful for simple conditional assignments.