Move int i declaration outside the loop