// for (item in collection) { // // code, that typically references item // // runs # times for |collection| // } fun loopingCharsInString() { for (c in "howdy") { println(c) } } fun loopingIntsInRangesProgressions() { for (num in 1..5) { val numSquared = num * num println("$num squared is $numSquared") } for (seconds in 5 downTo 1) { println("$seconds second(s) to go!") } println("Happy New Year!!") } fun loopingLists() { fun sayHello(name: String) { println("Howdy, $name!") } val characters = listOf("Harry", "Hermione", "Ron") for (student in characters) { sayHello(student) } } fun loopingMixed() { val letters = listOf("a", "b", "c") val numbers = listOf(1, 2, 3) for (idx in letters.indices) { println("At index $idx, you'll find '${ letters[ idx ] }'") } // last homework? for (idx in letters.indices) { println("easy as ${ letters[idx] }${ numbers[idx] }") } } fun loopingNested(names: List, excitementLevel: Int) { for (name in names) { print("Hello, $name") for (num in 1..excitementLevel) { print("!") } println() } } fun main() { loopingCharsInString() loopingIntsInRangesProgressions() loopingLists() loopingMixed() loopingNested( listOf("alice", "bob", "chris"), 7 ) } main()