Between test
Learn how to check if a value is between two other values.
This test checks whether a value is between two other values. In terms of semantics, this test is equivalent to chaining relational operations.
You can choose whether the test is inclusive or exclusive. That is, you can decide whether or not the value can be equal to the lower or upper bound. By default, the test is inclusive.
This test inherits the short-circuit optimization from the logical operation. This means that if the lower-bound condition fails, the evaluation of the upper-bound condition is skipped.
Syntax
This test has the following syntax:
/*<value>*/ is between /*<lower-bound>*/ and /*<upper-bound>*/
To negate the test, you can write:
/*<value>*/ is not between /*<lower-bound>*/ and /*<upper-bound>*/
You can also specify whether the test is inclusive or exclusive:
/*<value>*/ is between /*<lower-bound>*/ and /*<upper-bound>*/ <bound-type>
The following bound types are supported:
Bound type | Description |
---|---|
inclusive | Includes the lower and upper bounds when checking whether the value is between them. This is the default bound type. |
exclusive | Excludes the lower and upper bounds when checking whether the value is between them. |
Parameters
These are the supported parameters:
- value
The value to compare with two other values.
- lower-bound
The lower bound.
- upper-bound
The upper bound.
Examples
Here is a basic example of how to check whether a value is between two other values:
1 is between 1 and 3 // true
To make the test exclusive, you can write:
1 is between 1 and 3 exclusive // false
It also works with date and time values:
today is between yesterday and tomorrow // true