between(int x, int lower, int upper): bool

between(var x, var lower, var upper): bool

Returns true when the variable x lies within a lower and upper border. When lower is above upper, returns true when either x >= upper or x <= lower, this way allowing the comparison of cyclic ranges such as hours of the day or months of the year.

Parameters:

x, lower, upper - any var or int.

Algorithm:

if(lower <= upper) 
  return (x >= lower) and (x <= upper); 
else<
  return (x >= lower) or (x <= upper);

Example:

if(between(x,0.,1.))
  ...  // executed when x is between 0..1
if(between(hour(),22,4))
  ...  // executed when hour() is above 22 or below 4

See also:

sqrt, abs, sign, clamp, min, max, ifelse

► latest version online