case 容許咱們對不少模式的值進行比較 直到找到匹配的less
--》不要想成 switch casecode
iex(58)> x = 1
1
iex(59)> case 10 do
...(59)> x -> "1000"
...(59)> _ ->"200"
...(59)> end
"1000"it
對一個現存的變量進行模式匹配,你須要^
操做符
iex(60)> x = 1
1
iex(61)> case 10 do
...(61)> ^x -> "1000"
...(61)> _ -> "200"
...(61)> end
"200"變量
cond 找出第一個爲真的co
相似switch case 或者 else ifcas
iex(65)> cond do
...(65)> 2+2 == 5 -> "11111"
...(65)> 1+1 == 2 ->"222"
...(65)> end
"222"
if 和 unless
iex> if true do ...> "This works!" ...> end "This works!"
iex> unless true do ...> "This will never be seen" ...> end nil
if --else
iex> if nil do ...> "This won't be seen" ...> else ...> "This will" ...> end "This will"