title: Nested iteration in Scala
body: <p>What is the difference (if any) between two code fragments below?</p>
  
  <p>Example from Ch7 of Programming i Scala</p>
  
  <pre><code>def grep(pattern: String) = 
    for (
      file &lt;- filesHere
      if file.getName.endsWith(".scala");
      line &lt;- fileLines(file)
      if line.trim.matches(pattern)
    ) println(file + ": " + line.trim)
  </code></pre>
  
  <p>and this one</p>
  
  <pre><code>def grep2(pattern: String) = 
    for (
      file &lt;- filesHere
      if file.getName.endsWith(".scala")
    ) for (
      line &lt;- fileLines(file)
      if line.trim.matches(pattern)
    ) println(file + ": " + line.trim)
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>for (i &lt;- 1 to 2)
    for (j &lt;- 1 to 2)
      println(i, j)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>for (
    i &lt;- 1 to 2;
    j &lt;- 1 to 2
  ) println(i, j)
  </code></pre>