33 lines
598 B
Kotlin
33 lines
598 B
Kotlin
package ControlFlow
|
|
|
|
/**
|
|
* https://www.tutorialspoint.com/kotlin/kotlin_for_loop.htm
|
|
*/
|
|
class ForStatements {
|
|
fun main1(args: Array<String>) {
|
|
for (item in 1..5) {
|
|
println(item)
|
|
}
|
|
}
|
|
|
|
fun main2(args: Array<String>) {
|
|
for (item in 5 downTo 1 step 2) {
|
|
println(item)
|
|
}
|
|
}
|
|
|
|
fun main3(args: Array<String>) {
|
|
var fruits = arrayOf("Orange", "Apple", "Mango", "Banana")
|
|
for (item in fruits) {
|
|
println(item)
|
|
}
|
|
}
|
|
|
|
fun main4(args: Array<String>) {
|
|
var fruits = arrayOf("Orange", "Apple", "Mango", "Banana")
|
|
for (index in fruits.indices) {
|
|
println(fruits[index])
|
|
}
|
|
}
|
|
}
|