Why is this syntax not valid? The error IntelliJ reports is that only expressions are allowed in such context (line 2). I am wondering if there is some syntax to use to get around this, as Java allowed this type of assignment in loop feature.
var c: Int;
while ((c = reader.read()) != 1) {
}
The syntax is not valid, because c = reader.read()
is not an expression in Kotlin – this prevents all the ==
vs =
bugs.
You have to rewrite it as:
while (true) {
val c = reader.read()
if (c == 1) break
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With