如果语句逻辑错误

If statement logic error

本文关键字:错误 语句 如果      更新时间:2023-10-16
if ((pCommandPts>=tempChar.commandValue) && ((pCommandPts - tempChar.commandValue)<=0))

如果 pCommandPts 是值为 6 的 int,而 tempChar.commandValue 是值为 3 的 int,为什么此语句的计算结果为 false?

此表达式的左部分在 63 的情况下为真,但6-3不小于或等于零

&& ((pCommandPts - tempChar.commandValue)<=0))

该代码毫无意义,几乎可以肯定是一个错误。

如果重新排列不等式,则会得到:

 a >= b && a <= b

这只有在a == b的情况下才是正确的,这对你的情况6 != 3