The loop variable changes before the defer executes, so we need to pass it to the function to make sure the closure has the correct version of the loop variable.