You should put the if statement outside for to avoid branching multiple times.