if check out of for loop