Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not privy to inside information on the actual reasons, but my suspicion is very simple. Scala makes side-effectful loops awkward to use so that programmers will naturally prefer for-comprehensions.</p> <p>It does this in many ways. For instance, you don't have a <code>for</code> loop where you declare and mutate a variable. You can't (easily) mutate state on a <code>while</code> loop at the same time you test the condition, which means you often have to repeat the mutation just before it, and at the end of it. Variables declared inside a <code>while</code> block are not visible from the <code>while</code> test condition, which makes <code>do { ... } while (...)</code> much less useful. And so on.</p> <p>Workaround:</p> <pre><code>while ({bytesRead = in.read(buffer); bytesRead != -1}) { ... </code></pre> <p>For whatever it is worth.</p> <p>As an alternate explanation, perhaps Martin Odersky had to face a few very ugly bugs deriving from such usage, and decided to outlaw it from his language.</p> <p><strong>EDIT</strong></p> <p><a href="https://stackoverflow.com/users/243300/pollak">David Pollack</a> has <a href="https://stackoverflow.com/questions/1998724/what-is-the-motivation-for-scala-assignment-evaluating-to-unit-rather-than-the-va/2000517#2000517">answered</a> with some actual facts, which are clearly endorsed by the fact that <a href="https://stackoverflow.com/users/210303/martin-odersky">Martin Odersky</a> himself commented his answer, giving credence to the performance-related issues argument put forth by Pollack.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload