Wrap the loop in a closure