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

  • 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.

主站蜘蛛池模板: 武川县| 巫溪县| 开鲁县| 凤庆县| 扎囊县| 宁远县| 大渡口区| 鹿泉市| 阿拉尔市| 大新县| 吉安县| 河北省| 衡阳县| 敦化市| 焉耆| 枝江市| 新兴县| 甘德县| 益阳市| 阿坝县| 南平市| 那坡县| 阿巴嘎旗| 施秉县| 曲沃县| 宜阳县| 合江县| 尼勒克县| 广东省| 垫江县| 南澳县| 金沙县| 资源县| 九寨沟县| 当雄县| 贵南县| 乡城县| 乐业县| 贵溪市| 云和县| 长子县|