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

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

主站蜘蛛池模板: 洛阳市| 厦门市| 北辰区| 滁州市| 色达县| 昌宁县| 武鸣县| 威信县| 鸡西市| 新营市| 封开县| 西昌市| 斗六市| 卫辉市| 阿拉尔市| 渭源县| 巢湖市| 同仁县| 拉萨市| 吉木萨尔县| 中西区| 务川| 晋宁县| 来宾市| 湟中县| 贞丰县| 启东市| 百色市| 萍乡市| 绩溪县| 阿坝县| 河源市| 奉贤区| 靖边县| 界首市| 舞阳县| 锦屏县| 辽宁省| 凭祥市| 曲水县| 西吉县|