// inclusive [1, 5] val r1: IntRange = 1..5 // println("$r1: ${ r1.toList() }") // exclusive [1, 5) val r2 = 1 until 5 // println("$r2: ${ r2.toList() }") // Odds in [1, 5] val p1: IntProgression = 1..5 step 2 // println("$p1: ${ p1.toList() }") // Reverse order val p2 = 5 downTo 1 // println("$p2: ${ p2.toList() }") // PRO TIP via in/!in // compare: (5 >= 1) && (5 <= 5) // println(5 in r1) // compare !((5 >= 1) && (5 < 5)) // println(5 !in r2) // PRO TIP with lists // what are the valid indices? // println(listOf(2, 5, 0, 0).indices) // "slice": get a subset of a list // println(listOf(2, 5, 0, 0).slice(1..2)) // Many other cool functions :) // https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-range/ // https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/-int-progression/ // how many?: .count() // any values?: .isEmpty() // add up: .sum() // biggest/smallest: .min()/max() // ABSTRACTIONS!! fun countdown(start: Int) { fun excite(num: Int) { println("$num!") } (start downTo 1).forEach(::excite) println("Happy New Year!!") } // countdown(5)