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

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.

主站蜘蛛池模板: 肥乡县| 新沂市| 大邑县| 咸丰县| 灌云县| 都昌县| 玉环县| 克东县| 尤溪县| 三亚市| 密山市| 开封市| 泾源县| 定结县| 衡阳市| 汾阳市| 深州市| 南漳县| 资兴市| 始兴县| 临颍县| 任丘市| 来宾市| 于田县| 分宜县| 凉城县| 庆安县| 垫江县| 化隆| 那坡县| 阳山县| 卢氏县| 乐亭县| 杭锦后旗| 磴口县| 长丰县| 嘉兴市| 五莲县| 莒南县| 浦东新区| 红原县|