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>*/
Try in Playground

To negate the test, you can write:

/*<value>*/ is not between /*<lower-bound>*/ and /*<upper-bound>*/
Try in Playground

You can also specify whether the test is inclusive or exclusive:

/*<value>*/ is between /*<lower-bound>*/ and /*<upper-bound>*/ <bound-type>
Try in Playground

The following bound types are supported:

Bound typeDescription
inclusiveIncludes the lower and upper bounds when checking whether the value is between them. This is the default bound type.
exclusiveExcludes 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
Try in Playground

To make the test exclusive, you can write:

1 is between 1 and 3 exclusive // false
Try in Playground

It also works with date and time values:

today is between yesterday and tomorrow // true
Try in Playground