> In my current class, we are required to assess our own code, as well as 2 random > other students' code. It is pseudo code, so it doesn't really conform to a specific > language, so I must ask: Will the following work in ANY language? > > If Variable NOT == 0
NOT is an unary operator. == (equal to) is a binary operator. Placing the NOT there will make it negate the equal to operator. So that specific syntax has to fail in every language I know of. Only these constructs would work, be it pseudocode or real code in a specific language: if variable == not(0) if not(variable == 0)
One could argue that in certain situations, a minus sign (-) is also an unary operator but it wouldn't matter in this example since the operator precedence would unambiguously interpret the following in the same way: if variable == not -1 if variable == not(-1)
However even if you forget about operator precedence and specify parentheses all around everything, it's clear that the construct you ask about doesn't make sense: if variable not(== 0)
Operator precedence has always been one of my weak spots in writing code so I tend to overuse parentheses to ensure that things are interpreted in the way I need.
Wound up, can't sleep, can't do anything right, little honey / Oh, since I set my eyes on you. / I tell you the truth. I can't get it right / Get it right / Since I met you...
|