title: scala foreach with Unit passed in
body: <p>I'm a very beginner to Scala and please excuse my ignorance.</p>
  
  <p>Here is a snippet whose behavior is a bit strange to understand.</p>
  
  <p><code>def times(n: Int) = (body: Unit) =&gt; (0 until n) foreach(n=&gt;body)</code></p>
  
  <p><code>times(5){
          println("index")
      }</code></p>
  
  <p>The output is: index printed only once.</p>
  
  <p>However, this one:</p>
  
  <p><code>def times(n: Int) = (0 until n) foreach(n=&gt;println("index"))</code></p>
  
  <p>prints it 10 times.</p>