# 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:** 2

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 20, 2020, 3:32pm UTC](https://verificationacademy.com/forums/t/can-we-use-ternary-operator-in-constraints/37607/2 "2020-05-20T15:32:06Z")

</div>

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

Your problem is the precedence of the equality ‘==’ operator is higher than the conditional operator ‘?:’. What you wrote gets interpreted as:

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

```

This leaves b unconstrained since any value of b results in the expression being non-zero(true).

---

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