# Can we use Ternary operator in Constraints?

**URL:** <https://verificationacademy.com/forums/t/can-we-use-ternary-operator-in-constraints/37607>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, constraints\
**Created:** [May 20, 2020, 9:37am UTC](https://verificationacademy.com/forums/t/can-we-use-ternary-operator-in-constraints/37607 "2020-05-20T09:37:15Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![MICRO\_91](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@MICRO\_91](https://verificationacademy.com/forums/u/MICRO_91)\
**Post date:** [May 21, 2020, 1:50am UTC](https://verificationacademy.com/forums/t/can-we-use-ternary-operator-in-constraints/37607/4 "2020-05-21T01:50:03Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/can-we-use-ternary-operator-in-constraints/37607/3):_

Hi Dave ,

(1) If ‘==’ takes precedence shouldn’t b be constrained to 1 since ( a \< 2 ) would return 1 ( due to in-line constraint a == 1 ; )

(2) Also I didn’t get " since any value of b results in the expression being non-zero(true). "

What if I were to change constraint to ::

```verilog
 b == (a<2) ? 0 : 3; 

```

Would the 0 ( since a == 1 ) play any part ?

Thanks .

---

_[View the full topic](https://verificationacademy.com/forums/t/can-we-use-ternary-operator-in-constraints/37607)._
