title: Why is the value not being returned as it should be here?
body: <p>Why does this work?</p>
  
  <pre><code>object Foo extends App {
    def bar(s: String): String = {
      if (s.size == 0) "empty string"
      else if (s.size == 1) s + s
      else s.head + bar(s.tail)
    }
  
    println(bar(""))
    println(bar("s"))
    println(bar("soom"))
  }
  
  [info] Running example.Foo
  empty string
  ss
  soomm
  </code></pre>
  
  <p>While this one doesn't.</p>
  
  <pre><code>object Foo extends App {
    def bar(s: String): String = {
      if (s.size == 0) "empty string"
      if (s.size == 1) s + s
      s.head + bar(s.tail)
    }
  
    println(bar(""))
    println(bar("s"))
    println(bar("soom"))
  }
  
  java.util.NoSuchElementException: next on empty iterator
  </code></pre>
  
  <p>Shouldn't the <code>return</code>s short-circuit the code and not go forward? I feel that there's a simple explanation to why the second code snippet is not working, but I can't seem to find out why.</p>