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

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.

主站蜘蛛池模板: 湘西| 罗平县| 广汉市| 平顶山市| 遵义县| 雷山县| 广河县| 庄河市| 搜索| 偏关县| 长宁区| 丹凤县| 图木舒克市| 包头市| 镇巴县| 定日县| 河池市| 柘荣县| 大兴区| 宜昌市| 南城县| 宁蒗| 宜宾县| 清水河县| 哈密市| 澄城县| 翼城县| 桓台县| 石阡县| 务川| 宜春市| 肥东县| 黄龙县| 广平县| 阜南县| 宁南县| 巴楚县| 固镇县| 西林县| 筠连县| 阜康市|