cond do
0 == 1 -> IO.puts "0 = 1"
2 == 1 + 1 -> IO.puts "1 + 1 = 2"
3 == 1 + 2 -> IO.puts "1 + 2 = 3"
end
# Outputs "1 + 1 = 2" (first condition evaluating to true)
cond
will raise a CondClauseError
if no conditions are true.
cond do
1 == 2 -> "Hmmm"
"foo" == "bar" -> "What?"
end
# Error
This can be avoided by adding a condition that will always be true.
cond do
... other conditions
true -> "Default value"
end
Unless it is never expected to reach the default case, and the program should in fact crash at that point.