IF statement question

Hello,

I am receiving a number from Sockets that gets placed into a variable “command”. I am trying to test to see of that number is a certain number:
IF command<>42 OR command<>105 OR command<>106 OR command<>5 THEN
SocketSend clientSocket\Str:=“Unknown command”;
GOTO MainLoopEnd;
ENDIF

I am sending it the number 42, and it still goes into this IF statement. However, if I compare just IF command<>42 (not all the other OR command<>#'s), it works just fine and skips this loop.
So my question is, how can I compare multiple values? What am I doing wrong? Is there like a certain hierarchy thing I am missing?

Thanks for any help!
SM

hello,
you should use AND instead of OR
IF command<>42 AND command<>105 AND command<>106 AND command<>5 THEN
so then the program enters the if loop if the number is different from 42,105,106,5

because if you use OR, it will always enter the IF because 42<>105

You can also write
IF NOT(command=42 OR command=105 OR command=106 OR command=5) THEN
it reads more logical to test that the number is outside of possible commands

Similarly I want to check if a given target approaches singularity so I am checking the joint angles, and if they come within +/- 0.1 degrees, I want to set bool singularity=true, otherwise return false:
IF ((target.robax.rax_5>-0.1) AND (target.robax.rax_5<0.1)) OR ((target.robax.rax_4>-0.1) AND (target.robax.rax_4<0.1)) THEN
singularity:=TRUE;
ELSE
singularity:=FALSE;
ENDIF
RETURN singularity;

Is there a way that I can do that?

Thanks,
SM

Is your question about if the approach to check singularity correct or about your code…? Because your description of checking the angle already match the code right?

There is a more short-hand notation:

singularity := Abs(target.robax.rax_4)<0.1 OR Abs(target.robax.rax_5)<0.1;