title: Can a while loop evaluate to a value?
body: <p>I'm learning Rust and today I stumbled upon being able to assign variables through <code>if</code>/<code>else</code> expressions. For instance:</p>
  
  <pre><code>let y = 5;
  
  let x = if y &gt; 20 { 20 } else { y };
  </code></pre>
  
  <p>Is there some way to do this with a <code>while</code> loop? I tried:</p>
  
  <pre><code>fn main() {
      let mut n = 0;
  
      let mut num = 0;
  
      num += while n &lt; 10 {
          n += 1;
          5
      };
  }
  </code></pre>
  
  <p>with the hope that <code>num</code> would eventually be equal to 50, with the while loop incrementing <code>num</code> by five each iteration, but I get the following error</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:8:9
    |
  8 |         5
    |         ^ expected (), found integral variable
    |
    = note: expected type `()`
               found type `{integer}`
  
  error[E0277]: cannot add-assign `()` to `{integer}`
   --&gt; src/main.rs:6:9
    |
  6 |     num += while n &lt; 10 {
    |         ^^ no implementation for `{integer} += ()`
    |
    = help: the trait `std::ops::AddAssign&lt;()&gt;` is not implemented for `{integer}`
  </code></pre>
  
  <p>Naturally, I could put the <code>num += 5</code> inside the while loop, but that takes the fun out of it.</p>
  
  <p>This is my first day with Rust, so I don't even know if it's possible to do what I have in mind. Is this indeed possible? Am I making a syntax error?</p>
  
  <p>This is another version of the code I'm trying to run, but also fails to work:</p>
  
  <pre><code>fn main() {
      let mut num = 0;
  
      num += while num &lt; 50 {
          5
      };
  }
  </code></pre>