# How to use AND in Case and Switch statements

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-and-in-case-and-switch-statements/77300>\
**Category:** Ignition\
**Created:** [August 2, 2023, 6:28pm UTC](https://forum.inductiveautomation.com/t/how-to-use-and-in-case-and-switch-statements/77300 "2023-08-02T18:28:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amir\_Farmanbar](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Amir\_Farmanbar](https://forum.inductiveautomation.com/u/Amir_Farmanbar)\
**Post date:** [August 2, 2023, 6:28pm UTC](https://forum.inductiveautomation.com/t/how-to-use-and-in-case-and-switch-statements/77300/1 "2023-08-02T18:28:14Z")

</div>

I wonder is it possible to use AND in "Case" or "Switch" statement. I am keep getting error.

I need to do switch if value of two tags turns to 1 and 6:  
for example:  
"when MachineMode=1 and tag2=6 turns defined tag to 3 etc.  
see below  
Switch ({[.]../MachineStatus/MachineMode},1 && tag2=6,0,2,3,4,5,  
3,  
1,  
1,  
2,  
1,  
1,  
1)),0)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 2, 2023, 6:37pm UTC](https://forum.inductiveautomation.com/t/how-to-use-and-in-case-and-switch-statements/77300/2 "2023-08-02T18:37:41Z")

</div>

No, you cannot. Switch operates on a single input, and the `&&` operator automatically returns a boolean, so you'll only have two possible inputs to your switch (true and false).  
Try to write out the truth table you're aiming for.  
When MachineMode is 1 and Tag2 is 6, the output is what?  
When MachineMode is not 1 and Tag2 is 6, the output is what?  
When MachineMode is 1 and Tag2 is not 6, the output is what?  
When MachineMode is not 1 and Tag2 is not 6, the output is what?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 2, 2023, 6:53pm UTC](https://forum.inductiveautomation.com/t/how-to-use-and-in-case-and-switch-statements/77300/3 "2023-08-02T18:53:37Z")

</div>

A simple solution:

```auto
case(tag2 * 100 + {[.]../MachineStatus/MachineMode},
    0, "black",
    2, "brown",
    100, "gray",
    102, "yellow",
    206, "blue",
    "white" // default
)

```

[https://docs.inductiveautomation.com/display/DOC81/case](https://docs.inductiveautomation.com/display/DOC81/case)
