title: Why Scala return in for-loop give Unit value type?
body: <p>I have written a for loop to traverse Map, I want this function return key immediately when found some value <strong>(both of key and value is Int type)</strong></p>
  
  <pre><code>var hs:Map[Int,Int] = Map(1 -&gt; 1, 2 -&gt; 2)
  for ((k,v) &lt;- hs) {
    if (v == 1)
      return k   
  }
  </code></pre>
  
  <p>but, scala give me the error message:</p>
  
  <pre><code>error: type mismatch;
   found   : Unit
   required: Int
    for ((k,v) &lt;- hst)
               ^
  one error found
  </code></pre>
  
  <p>then I change to </p>
  
  <pre><code>var result = 0
  for ((k, v) &lt;- hst){
    if (v == 1)
      result = k
  }
  result
  </code></pre>
  
  <p>then, it works well. Why the first version has type issues?</p>