title: Assignment not allowed in while expression?
body: <p>In Java we can usually perform an assignment within the <code>while</code> condition. However Kotlin complains about it. So the following code does not compile:</p>
  
  <pre><code>val br = BufferedReader(InputStreamReader(
          conn.inputStream))
  
  var output: String
  println("Output from Server .... \n")
  while ((output = br.readLine()) != null) { // &lt;--- error here: Assignments are not expressions, and only expressions are allowed in this context
      println(output)
  }
  </code></pre>
  
  <p>According to this other <a href="https://discuss.kotlinlang.org/t/assignment-not-allow-in-while-expression/339/6" rel="noreferrer">thread</a>, this seems the best solution:</p>
  
  <pre><code>val reader = BufferedReader(reader)
  var line: String? = null;
  while ({ line = reader.readLine(); line }() != null) { // &lt;--- The IDE asks me to replace this line for while(true), what the...?
    System.out.println(line);
  }
  </code></pre>
  
  <p>But is it?</p>