Soni They/Them L. <fakedme@gmail.com> wrote:
On 2018-01-28 01:58 PM, Paige DePol wrote:
However, in a switch/case with a mix of constant and non-constant case blocks
the constant ones would be checked first via lookup table, and if that failed
then the non-constant blocks would be checked via if/else, and if all blocks
failed the 'else' block would be executed.
But what if a non-constant case comes first, and the constant case has the
same value? Shouldn't the non-constant case run, rather than the constant
case? I think it should.
Mixing constant and non-constant values in a switch block is always going to
have some trade offs. In the case where there would be conflict like you've
mentioned it would then be up to the coder to use the most relevant construct.
If I were to allow constant and non-constant values in case blocks, which
after all this discussion I am not even sure is a good idea, I would say
the constant value lookup would be done followed by the if/else construct
for non-constant values. Thus the constant values would have priority.
Otherwise, for the example you gave... just use if/else in the first place,
or only use non-constant or non-conflicting values as case values?
~Paige