The variable declaration should be moved out of the loop.