- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 89字
- 2021-07-23 19:05:49
How it works...
We have used a range expression together with the in operator in order to define a condition for the if statement. The condition statement is natural to read and concise. In contrast, an equivalent classic implementation would look like this:
val randomInt = Random(20).nextInt()
if (randomInt >= 0 && randomInt <= 10) {
print("$randomInt belongs to <0, 10> range")
} else {
print("$randomInt doesn't belong to <0, 10> range")
}
No doubt, the declarative approach using the range and in operator is cleaner and easier to read, compared to classic, imperative-style condition statements.
推薦閱讀
- FuelPHP Application Development Blueprints
- Learning Cython Programming(Second Edition)
- MySQL 8從入門到精通(視頻教學(xué)版)
- 軟件界面交互設(shè)計(jì)基礎(chǔ)
- Neo4j Essentials
- Python算法指南:程序員經(jīng)典算法分析與實(shí)現(xiàn)
- 利用Python進(jìn)行數(shù)據(jù)分析
- 編程菜鳥(niǎo)學(xué)Python數(shù)據(jù)分析
- Getting Started with React Native
- RubyMotion iOS Develoment Essentials
- HTML5+CSS3+JavaScript 從入門到項(xiàng)目實(shí)踐(超值版)
- Mastering PowerCLI
- AI輔助編程Python實(shí)戰(zhàn):基于GitHub Copilot和ChatGPT
- Swift 2 Blueprints
- Java基礎(chǔ)案例教程(第2版)