Assignment not allowed in while expression?

前端 未结 5 844
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 06:28

In Java we can usually perform an assignment within the while condition. However Kotlin complains about it. So the following code does not compile:



        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 07:11

    Here is the shortest solution powered by stdlib that also safely closes the reader:

    reader.forEachLine {
        println(it)
    }
    

提交回复
热议问题