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

Getting ready

The Kotlin standard library provides a convenient way of creating progression with a custom step value. We can do so using an extension function for progressions of integral types called step(). We can also benefit from the infix notation and declare a progression with a custom step, as follows:

val progression: IntProgression = 0..1000 step 100

If we were to use progression in the for loop, it would iterate 10 times:

val progression: IntProgression = 0..1000 step 100
for
(i in progression) {
println(i)
}

We could also achieve the same result by iterating with the while loop, as follows:

var i = 0
while (i <= 1000) {
println(i)
i += 100
}
主站蜘蛛池模板: 永清县| 滦南县| 潮安县| 洛隆县| 进贤县| 通道| 中牟县| 台中县| 大丰市| 西贡区| 涡阳县| 会宁县| 萨迦县| 枣强县| 阿拉善左旗| 天峨县| 巴彦淖尔市| 麻栗坡县| 雷山县| 呼和浩特市| 遂溪县| 潼南县| 平塘县| 云南省| 武胜县| 文登市| 灵山县| 长宁县| 齐河县| 黑山县| 资中县| 新乡县| 桐柏县| 武宣县| 永丰县| 化德县| 石林| 加查县| 肇州县| 鲁甸县| 凌源市|