elixir - 6 case, cond , if
访问量: 1366
case:
iex(1)> a = 1
1
iex(2)> case a do
...(2)> 1 -> 'good'
...(2)> _ -> 'lala'
...(2)> end
'good'
注意上面的 _ 代表了 其他情况
cond
cond do
...(3)> 1 + 1 == 3 -> 'not this'
...(3)> 1 * 2 == 6 -> 'not this'
...(3)> true -> 'this good'
...(3)> end
'this good'
if ,unless
iex(4)> if true do
...(4)> 'good'
...(4)> else
...(4)> 'bad'
...(4)> end