Advantage of switch over if-else statement

后端 未结 22 2537
梦谈多话
梦谈多话 2020-11-22 11:08

What\'s the best practice for using a switch statement vs using an if statement for 30 unsigned enumerations where about 10 have an ex

22条回答
  •  面向向阳花
    2020-11-22 11:56

    Use switch, it is what it's for and what programmers expect.

    I would put the redundant case labels in though - just to make people feel comfortable, I was trying to remember when / what the rules are for leaving them out.
    You don't want the next programmer working on it to have to do any unnecessary thinking about language details (it might be you in a few months time!)

提交回复
热议问题