# If, else in expression or use jython?

**URL:** <https://forum.inductiveautomation.com/t/if-else-in-expression-or-use-jython/860>\
**Category:** Archived Topics\
**Created:** [October 30, 2008, 8:41pm UTC](https://forum.inductiveautomation.com/t/if-else-in-expression-or-use-jython/860 "2008-10-30T20:41:57Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [January 31, 2020, 7:15pm UTC](https://forum.inductiveautomation.com/t/if-else-in-expression-or-use-jython/860/5 "2020-01-31T19:15:17Z")

</div>

The closest expression equivalent of elif is nested if statements. It's not quite as elegant and must include a final else (unlike Python scripts):

```java
// Start with an if.
if(condition, 1,
	// Nest if to get equivalent of elif.
	if(condition, 2,
		// With expressions you always have an else value at the end.
		0
	)
)

```

In most cases, binEnum would be an elegant replacement for the above nested ifs. See [examples](http://forum.inductiveautomation.com/t/if-statement/6102/14) in the other thread you posted in.

The switch expression isn't a viable replacement for elif unless you're using elif to evaluate different values of a _single_ condition.

> [@If Statement](http://forum.inductiveautomation.com/t/if-statement/6102/15):
>
> Use [switch](https://docs.inductiveautomation.com/display/DOC80/switch) or [case](https://docs.inductiveautomation.com/display/DOC80/case) to get different results for different values of a single tag/property. Use [binEnum](https://docs.inductiveautomation.com/display/DOC80/binEnum) (to get index of first true condition) or [binEnc](https://docs.inductiveautomation.com/display/DOC80/binEnc) (to get a single value representing state of all conditions) for multiple true/false conditions.

---

_[View the full topic](https://forum.inductiveautomation.com/t/if-else-in-expression-or-use-jython/860)._
