# Conditional statements inside an expression switch statement

**URL:** <https://forum.inductiveautomation.com/t/conditional-statements-inside-an-expression-switch-statement/18569>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [June 21, 2018, 5:54pm UTC](https://forum.inductiveautomation.com/t/conditional-statements-inside-an-expression-switch-statement/18569 "2018-06-21T17:54:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![awaege](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@awaege](https://forum.inductiveautomation.com/u/awaege)\
**Post date:** [June 21, 2018, 5:54pm UTC](https://forum.inductiveautomation.com/t/conditional-statements-inside-an-expression-switch-statement/18569/1 "2018-06-21T17:54:28Z")

</div>

Hi. I’m having some issues with an expression that I am writing for an expression tag within a UDT. I want the expression to run differently depending upon a property (deviceType) that is part of the UDT. I can’t seem to find why it won’t work. I keep getting an evaluation error on the tag. Any help is appreciated.  
Here is the code:

```auto
switch(
{deviceType}, // value (string)
'HMI', //case 1
'PLC', //case 2
'Switch', //case 3
'SwitchCisco', //case 4
({[.]Ping_Status} = '1'), //return for HMI
({[.]OPC_Status} & ( {[.]Ping_Status} = '1')), //return for PLC
(({[.]OPC_Status} != 1) & ( {[.]Ping_Status} = '1')), //return for Switch
({[.]Ping_Status} = '1'), //return for SwitchCisco
False) //default

```

The Ping Status tag is a query tag within the UDT and the OPC Status tag is an OPC tag within the UDT

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 21, 2018, 6:02pm UTC](https://forum.inductiveautomation.com/t/conditional-statements-inside-an-expression-switch-statement/18569/2 "2018-06-21T18:02:43Z")

</div>

I think you’ll need {deviceType} in quotes, as it is a string that is evaluated at tag creation, not when the expression is run. You should know that this approach will evaluate all four subexpressions regardless of device type, then discard three of them. If any non-applicable expression fails, the whole expression will fail.  
Consider creating a “base” UDT and inherit it in four dependent UDTs, one for each type. The base UDT would leave this item out, so the dependent UDTs can define it differently.

---

<div class="post-metadata">

**Author:** ![AFULLER](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/afuller/32/7931_2.png) [@AFULLER](https://forum.inductiveautomation.com/u/AFULLER)\
**Post date:** [January 31, 2020, 6:14pm UTC](https://forum.inductiveautomation.com/t/conditional-statements-inside-an-expression-switch-statement/18569/3 "2020-01-31T18:14:53Z")

</div>

Can you provide an example?
