javascript break for loop inside if