android kotlin for loop example
Kotlin for loop is used to iterate a part of the program several times. It iterates through arrays, ranges, collections, or anything that provides for iterate. Kotlin for loop is equivalent to the for each loop in languages like C#.
The for loop in Kotlin iterates through anything that provides an iterator. In this article, you learn to create for loop (with the help of examples).
There is no traditional for loop in Kotlin unlike Java and other languages.
In Kotlin, for loop is used to iterate through ranges, arrays, maps and so on (anything that provides an iterator).
The syntax of for loop in Kotlin is:
for (item in collection) {
// body of loop
}
example for loop kotlin:
fun main(args: Array<String>) {
for (i in 1..5) {
println(i)
}
}
No comments:
Post a Comment