1 Answers
For loop in Kotlin.
fun main(args : Array<String>){
var nums = 1..10
for(a in nums)
{
println(a)
}
}
Output:
1
2
3
4
5
6
7
8
9
10
We can also increment in two steps or more steps, let’s see one example.
fun main(args : Array<String>){
var nums = 1..10
for(a in nums step 2)
{
println(a)
}
}
Output:
1
3
5
7
9