[ Arithmetic | Reference Manual | Alphabetic Index ]
between(+From, +To, +Step, -Result)
Generate integer values between From and To with Step increment.
- A variable or an integer
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
Fails if To is less than From (for positive Step), or From less than To (for negative Step)
- (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.
between(1, 4, 1, X).
between(5, 0, -2, X).
between(2, 10, 3, 8).
between(3, 3, 1, X).
between(2, 0, 1, X).
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)