Error in my code but it compiled anyway? if ( 10 < pressDuration < 1000 )

I wanted to check whether a value is in a certain range and I typed the following and it compiled and uploaded: if ( 10 < pressDuration < 1000 )

The functionality wasn't as expected and I figured the correct form is if ( 10 < pressDuration && pressDuration < 1000 ) but my question is, if what I did is invalid, why did it compile without an error? What is the compiler's interpretation of my invalid code?

It is not invalid, the compiler could make sense of it. However what the compiler thought it meant was not the same as you thought it meant.

I am guessing that the compiler first evaluated 10 < pressDuration into a logic true or false, and then compared that to see if this true or false was less than 1000.

1 Like

Yup.
1 (aka true) or 0 (aka false) is always less than 1000.

2 Likes

that's interesting -- never seen that during my career but AWOL summary explains it due to precedence