- 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.
推薦閱讀
- JavaScript修煉之道
- JavaScript高效圖形編程
- 深入理解Django:框架內(nèi)幕與實(shí)現(xiàn)原理
- Offer來了:Java面試核心知識(shí)點(diǎn)精講(原理篇)
- 基于免疫進(jìn)化的算法及應(yīng)用研究
- ASP.NET動(dòng)態(tài)網(wǎng)頁(yè)設(shè)計(jì)教程(第三版)
- Essential Angular
- Hands-On JavaScript High Performance
- Apache Mesos Essentials
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- Selenium Testing Tools Cookbook(Second Edition)
- NGINX Cookbook
- Node Cookbook(Second Edition)
- Scratch3.0趣味編程動(dòng)手玩:比賽訓(xùn)練營(yíng)
- 代碼閱讀