Use for loop instead of if statement