# Why I can't apply value inside while loop?

**URL:** <https://discuss.kotlinlang.org/t/why-i-cant-apply-value-inside-while-loop/7762>\
**Category:** Support\
**Created:** [May 11, 2018, 1:05pm UTC](https://discuss.kotlinlang.org/t/why-i-cant-apply-value-inside-while-loop/7762 "2018-05-11T13:05:46Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [May 11, 2018, 1:20pm UTC](https://discuss.kotlinlang.org/t/why-i-cant-apply-value-inside-while-loop/7762/3 "2018-05-11T13:20:05Z")

</div>

The Kotlin team decided against it for a few reasons I think. In most cases it is just considered bad style and it also makes code harder to read. Yes your example is the one valid place where this kind of feature would be pretty handy, but they decided against it still, because only a small numbers of libraries would actually use something like this and it’s not worth adding an new feature to the language just for that.  
Also there is a massive discussion about this here

> [@Assignment not allow in while expression?](https://discuss.kotlinlang.org/t/assignment-not-allow-in-while-expression/339):
>
> Hi, In Java, I can do thing like this: `` BufferedReader reader = new BufferedReader(reader); String line = null; while ((line = reader.readLine()) != null) { &nbsp;&nbsp;System.out.println(line); } However in Kotlin such thing is not allowed. I get error like “Assignments are not expressions, and only expressions are allowed in this context” So the best I can come up with is something like this, but I wonder is there a better to write this in Kotlin? I like the Java syntax better because it’s s…

---

_[View the full topic](https://discuss.kotlinlang.org/t/why-i-cant-apply-value-inside-while-loop/7762)._
