# If Statement

**URL:** <https://forum.inductiveautomation.com/t/if-statement/6102>\
**Category:** Ignition\
**Created:** [March 26, 2013, 1:57am UTC](https://forum.inductiveautomation.com/t/if-statement/6102 "2013-03-26T01:57:14Z")\
**Posts on this page:** 1\
**Showing post:** 14

<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, 6:49pm UTC](https://forum.inductiveautomation.com/t/if-statement/6102/14 "2020-01-31T18:49:17Z")

</div>

> [@AFULLER](#):
>
> IF(({[.]…/CTR\_VAC\_ROLL\_A\_MODE}\>0||{[.]…/CTR\_VAC\_ROLL\_B\_MODE\_TENSION}\>0),1,2)

Do you want a result of 1 if either of your first conditions is true and 2 if neither is true? If so, what you have should work, assuming the relative tag paths are correct.

Or do you want a result of 1 if the first condition is true and a result of 2 if the second condition is true? There are multiple ways to do this, depending on what result you want if both conditions are true or both are false. Here's an example using `if` that ignores the second condition if the first condition is true:

```java
// Return 1 if first condition is true (regardless of second condition).
if({[.]…/CTR_VAC_ROLL_A_MODE}>0, 1,
	// Return 2 if first condition is false and second condition is true.
	if({[.]…/CTR_VAC_ROLL_B_MODE_TENSION}>0, 2,
		// Return zero if neither is true.
		0
	)
)

```

A simpler way to get the same result would use [binEnum](https://docs.inductiveautomation.com/display/DOC80/binEnum):

```java
// Returns index of first true condition:
// 0 indicates both conditions false.
// 1 indicates first condition true, regardless of second condition.
// 2 indicates second condition true and first condition is false.
binEnum(({[.]…/CTR_VAC_ROLL_A_MODE}>0,{[.]…/CTR_VAC_ROLL_B_MODE_TENSION}>0)

```

Or use [binEnc](https://docs.inductiveautomation.com/display/DOC80/binEnc) to capture all possible states:

```auto
// 0 (binary 00) indicates both conditions false.
// 1 (binary 01) indicates first condition true.
// 2 (binary 10) indicates second condition true.
// 3 (binary 11) indicates both conditions true.
binEnc(({[.]…/CTR_VAC_ROLL_A_MODE}>0,{[.]…/CTR_VAC_ROLL_B_MODE_TENSION}>0)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/if-statement/6102)._
