In Java we can usually perform an assignment within the while condition. However Kotlin complains about it. So the following code does not compile:
while
And here is a short Kotlin-style general solution by Roman Elizarov:
while (true) { val line = reader.readLine() ?: break println(line); }
Here break has Nothing type that also helps to promote type inference for the line as non-nullable string.
break
line