title: Objective-C blocks
body: <p>Trying to understand how blocks working in objective-c. Got next question while reading apple's docs (<a href="http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/bxUsing.html" rel="nofollow">link</a>)</p>
  
  <p>Here is an example how we should no use blocks:</p>
  
  <pre><code>void dontDoThis() {
      void (^blockArray[3])(void);  // an array of 3 block references
  
      for (int i = 0; i &lt; 3; ++i) {
          blockArray[i] = ^{ printf("hello, %d\n", i); };
          // WRONG: The block literal scope is the "for" loop.
      }
  }
  </code></pre>
  
  <p>But how we could get 3 different blocks that will print "hello, 0", "hello, 1" and "hello, 2"? I tried many different ways but every time I got "hello, 2" three times.</p>