break for loop in if statement javascript