title: Groovy nested closures with using 'it'
body: <p>Code inside closures can refer to <code>it</code> variable.</p>
  
  <pre><code>8.times { println it }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>def mywith(Closure closure) {
     closure()
  }
  
  mywith { println it }
  </code></pre>
  
  <p>With this behavior in mind you can't expect following code to print <code>0011</code></p>
  
  <pre><code>2.times {
     println it 
  
     mywith {
        println it
     }
  }
  </code></pre>
  
  <p>And instead I have to write</p>
  
  <pre><code>2.times { i -&gt;
     println i 
  
     mywith {
        println i
     }
  }
  </code></pre>
  
  <p>My question is: why closures without parameters override <code>it</code> variable even if they don't need it.</p>