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

Getting ready

The Kotlin standard library provides functions that allow the declaration of ranges for the integral, primitive types, such as Int, Long, and Char. To define a new range instance, we can use the rangeTo() function. For example, we can declare a range of integers from 0 to 1000 in the following way:

val range: IntRange = 0.rangeTo(1000)

The rangeTo() function has also its own special operator equivalent, .., which allows the declaration of a range with a more natural syntax:

val range: IntRange = 0..1000

Also, in order to declare a range of elements in a decreasing order, we can use the downTo() function.

主站蜘蛛池模板: 绵竹市| 莲花县| 高要市| 仙游县| 固原市| 穆棱市| 桦南县| 县级市| 洪江市| 大田县| 新龙县| 琼结县| 怀集县| 新营市| 鹿泉市| 焦作市| 奎屯市| 新巴尔虎右旗| 永清县| 三明市| 宁阳县| 项城市| 镇巴县| 广南县| 遂川县| 调兵山市| 建平县| 措美县| 平原县| 霍山县| 贵溪市| 南城县| 石嘴山市| 绍兴县| 广汉市| 临漳县| 莆田市| 漳平市| 岚皋县| 泗阳县| 孟州市|