- Mastering Elixir
- André Albuquerque Daniel Caixinha
- 87字
- 2021-08-05 10:42:49
if and unless
These two constructs can be used with the following syntax:
if <expression> do
# expression was truthy
else
# expression was falsy
end
unless <expression> do
# expression was falsy
else
# expression was truthy
end
As with the def construct, they can be inlined. For if, you'd do this:
if <expression>, do: # expression was truthy, else: # expression was falsy
For both constructs, the else clause is optional. They will return nil if the main clause doesn't match and no else clause was provided.
推薦閱讀
- The Complete Rust Programming Reference Guide
- C語言程序設計案例教程(第2版)
- SOA實踐
- ASP.NET Core 2 and Vue.js
- 實戰Java高并發程序設計(第3版)
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(2)
- Python Interviews
- SwiftUI極簡開發
- ASP.NET 4.0 Web程序設計
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- Go語言入門經典
- INSTANT JQuery Flot Visual Data Analysis
- Java Web開發基礎與案例教程
- 編程的原則:改善代碼質量的101個方法
- 面向物聯網的Android應用開發與實踐