Can move for loop outside of if