KotlinExamples/src/main/kotlin/ControlFlow/ForStatements.kt

33 lines
598 B
Kotlin
Raw Normal View History

2021-12-27 22:39:05 +00:00
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])
}
}
}