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

前端 未结 24 933
一个人的身影
一个人的身影 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:39

    I'm reminded of when I first started to learn programming, in Basic, and at one point I wrote

    if X=3 OR 4
    

    I intended this like you are describing, if X is either 3 or 4. The compiler interpreted it as:

    if (X=3) OR (4)
    

    That is, if X=3 is true, or if 4 is true. As it defined anything non-zero as true, 4 is true, anything OR TRUE is true, and so the expression was always true. I spent a long time figuring that one out.

    I don't claim this adds anything to the discussion. I just thought it might be a mildly amusing anecdote.

提交回复
热议问题