[ Arithmetic | Reference Manual | Alphabetic Index ]

# between(+From, +To, +Step, -Result)

Generate integer values between From and To with Step increment.
From
Integer
To
Integer
Step
Integer
Result
A variable or an integer

## Description

When first called, this predicate checks that From is less than or equal to To (or greater than or equal if Step is negative) and if so, it binds Result to From. On backtracking it increments Result by Step until it is greater than To (less than To is Step is negative) and then it fails.

### Modes and Determinism

• between(+, +, +, -) is nondet

### Fail Conditions

Fails if To is less than From (for positive Step), or From less than To (for negative Step)

### Exceptions

(4) instantiation fault
Input arguments are not instantiated.
(5) type error
An argument is not an integer.
(6) out of range
Step is zero.
(24) number expected
An argument is not a number.

## Examples

```Success:
between(1, 4, 1, X).
between(5, 0, -2, X).
between(2, 10, 3, 8).
between(3, 3, 1, X).
Fail:
between(2, 0, 1, X).
Error:
between(1, 4, S, X).         (Error 4)
between(1, 4, 0.1, X).       (Error 5)
between(1, 4, 0, X).         (Error 6)
between(1, 4, 1, a).         (Error 24)
```