Why do most programming languages only have binary equality comparison operators?

前端 未结 24 1012
一个人的身影
一个人的身影 2020-12-08 14:20

In natural languages, we would say \"some color is a primary color if the color is red, blue, or yellow.\"

In every programming language I\'ve seen, that translates

24条回答
  •  无人及你
    2020-12-08 14:51

    You'll have to go a bit down the abstraction layer to find out the reason why. x86's comparison/jump instructions are binary (since they can be easily computed in a few clock cycles), and that's the way things have been.

    If you want, many languages offer an abstraction for that. In PHP, for example you could use:

    $isPrimaryColor = in_array($someColor, array('Red', 'White', 'Blue'));
    

提交回复
热议问题