declare var outside of loop