This is pretty inefficient compared to a switch, and long if clauses are fragile. Could you consider using an internal switch?