A Swift Snare from Shriram Krishnamurthi

Prof. Krishnamurthi has called my attention to another snare which he posted in 2014 here. The code creates closures in a loop with a var counter. The closures capture the value of the counter, so that each closure would be expected to capture a different value. But when invoked, each closure returns the same value.

Update (2/5/16): With the acceptance of a proposal to remove C-style for-loops, this snare will no longer exist once the proposal is implemented. Thank you to all the people who informed me of this change.