Code for "for loop" in Kotlin?

All QuestionsCategory: KotlinCode for "for loop" in Kotlin?
chetan shidling asked 4 years ago

I need short information.

1 Answers
chetan shidling answered 4 years ago

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