官术网_书友最值得收藏!

  • Mastering Elixir
  • André Albuquerque Daniel Caixinha
  • 107字
  • 2021-08-05 10:42:49

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 = 5
5
iex> 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.

主站蜘蛛池模板: 东兰县| 长海县| SHOW| 广宗县| 五常市| 柳州市| 宜宾县| 张家川| 广元市| 永靖县| 科尔| 元朗区| 和平县| 平阳县| 乐安县| 米脂县| 栾城县| 泰兴市| 绥中县| 汽车| 浦东新区| 遵化市| 广宗县| 三江| 金溪县| 张家港市| 莲花县| 仁化县| 定远县| 克东县| 晋州市| 文登市| 西藏| 常州市| 南郑县| 安康市| 寻甸| 盐山县| 江口县| 新源县| 海南省|