Advantage of switch over if-else statement

后端 未结 22 2160
梦谈多话
梦谈多话 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:44

    The Switch, if only for readability. Giant if statements are harder to maintain and harder to read in my opinion.

    ERROR_01 : // intentional fall-through

    or

    (ERROR_01 == numError) ||

    The later is more error prone and requires more typing and formatting than the first.

提交回复
热议问题