# IF statement question

**URL:** <https://tech-community.robotics.abb.com/t/if-statement-question/7276>\
**Category:** RobotStudio\
**Tags:** robotstudio, socket, rapid-code, if-statements\
**Created:** [July 20, 2016, 2:06pm UTC](https://tech-community.robotics.abb.com/t/if-statement-question/7276 "2016-07-20T14:06:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveMob](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/stevemob/32/1600_2.png) [@SteveMob](https://tech-community.robotics.abb.com/u/SteveMob)\
**Post date:** [July 20, 2016, 2:06pm UTC](https://tech-community.robotics.abb.com/t/if-statement-question/7276/1 "2016-07-20T14:06:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kioog](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kioog](https://tech-community.robotics.abb.com/u/kioog)\
**Post date:** [July 20, 2016, 2:22pm UTC](https://tech-community.robotics.abb.com/t/if-statement-question/7276/2 "2016-07-20T14:22:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SteveMob](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/stevemob/32/1600_2.png) [@SteveMob](https://tech-community.robotics.abb.com/u/SteveMob)\
**Post date:** [July 20, 2016, 5:20pm UTC](https://tech-community.robotics.abb.com/t/if-statement-question/7276/3 "2016-07-20T17:20:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Verheij](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/john_verheij/32/1724_2.png) [@John\_Verheij](https://tech-community.robotics.abb.com/u/John_Verheij)\
**Post date:** [July 25, 2016, 7:41am UTC](https://tech-community.robotics.abb.com/t/if-statement-question/7276/4 "2016-07-25T07:41:15Z")

</div>

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:

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

```
