Step case

Sometimes we need to interact over values but with the arbitrary steps, not one by one, for example. Then we can use the step instruction. Let's practice:

for (i in 1..6 step 2) {  print(i)}

Here, we will see the following output: 135, because the interaction will start on the 1 value and will be increased by two points.

Awesome. The Kotlin ranges can add more readability to our source code and help to increase the quality of code as well.

Get Spring 5.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.