foreach in kotlin

foreach, kotlin

Solution

For other Kotlin newbees like me who are coming here just wanting to know how to loop through a collection, I found this in the documentation:

val names = listOf("Anne", "Peter", "Jeff")
for (name in names) {
    println(name)
}

Problem

I see an example in the official site: ``` fun main(args : Array<String>) { args filter {it.length() > 0} foreach {print("Hello, $it!")} } ``` But when I copied it to idea, it reports that `foreach` is a unresolved reference. What's the right code?

Original source