title: Best way to constrain a number between a lower and upper bound/limit
body: <p>I have a value that cannot go below a set value or above another set value. I have written a method to handle this for me. I am showing you two version of this same method written slightly different. One with multiple <code>if</code> statements and one with an <code>else if</code> tree. Both return the same result. <strong>But is one better than the other for some reason?</strong> Or (no kidding) is there a third, better way?</p>
  
  <pre><code>double Constrain(double low, double value, double high)
  {
      if (value &lt; low)
          return low;
      else if (value &gt; high)
          return high;
      else
          return value;
  }
  
  double Constrain(double low, double value, double high)
  {
      if (value &lt; low)
          return low;
      if (value &gt; high)
          return high;
      return value;
  }
  </code></pre>