- 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.
推薦閱讀
- 基于Java技術的Web應用開發
- Mastering matplotlib
- 程序員考試案例梳理、真題透解與強化訓練
- 營銷數據科學:用R和Python進行預測分析的建模技術
- Java Web程序設計
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優化計算
- Lua程序設計(第4版)
- C++ 從入門到項目實踐(超值版)
- C語言程序設計案例精粹
- Mastering Python Networking
- Mastering Rust
- Cocos2d-x學習筆記:完全掌握Lua API與游戲項目開發 (未來書庫)
- Mastering Python Design Patterns
- 案例式C語言程序設計實驗指導
- Illustrator CS6設計與應用任務教程