- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 121字
- 2021-07-23 19:05:47
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
}
推薦閱讀
- Getting Started with Citrix XenApp? 7.6
- Apache Spark 2 for Beginners
- 數(shù)據(jù)庫(kù)系統(tǒng)原理及MySQL應(yīng)用教程
- INSTANT MinGW Starter
- INSTANT Mercurial SCM Essentials How-to
- 網(wǎng)絡(luò)爬蟲(chóng)原理與實(shí)踐:基于C#語(yǔ)言
- PHP+MySQL網(wǎng)站開(kāi)發(fā)項(xiàng)目式教程
- C#程序設(shè)計(jì)
- Visual Basic程序設(shè)計(jì)
- AIRIOT物聯(lián)網(wǎng)平臺(tái)開(kāi)發(fā)框架應(yīng)用與實(shí)戰(zhàn)
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- Illustrator CS6設(shè)計(jì)與應(yīng)用任務(wù)教程
- Bootstrap for Rails
- Java 11 and 12:New Features
- Spring Boot學(xué)習(xí)指南:構(gòu)建云原生Java和Kotlin應(yīng)用程序