In Java we can usually perform an assignment within the while
condition. However Kotlin complains about it. So the following code does not compile:
No, the best way, IMO, would be
val reader = BufferedReader(reader)
reader.lineSequence().forEach {
println(it)
}
And if you want to make sure the reader is properly closed (as you would with a try-with-resources statement in Java), you can use
BufferedReader(reader).use { r ->
r.lineSequence().forEach {
println(it)
}
}