next() and previous() so we can use it in ranges.ĭef northToSouth = Īssert ntains(Compass. A range (or interval) defines the boundaries around a contiguous span of values of some Comparable type for example, integers from 1 to 100 inclusive. Object with next() and previous() can be used In Ada, an integer type is not specified in terms of. can produce the integer numbers in the range 1 (inclusive) and 6 (inclusive). So this means we can write our own objects so they can be used in ranges, but also we can use for example String objects or Enum values in a range.Īssert = ints Every integer in the inclusive range of the bounds is a valid value for the type. Roll the dice and return random number between 1 and 6 (both inclusive). < for an exclusive range.Įach object that implements the Comparable interface and implements a next() and previous() method can be used for a range. In the following example, we shall use the Kotlin range n downTo m. By default, m and n are included in the range. In this method, startInclusive (inclusive) and endExclusive (exclusive) are the two parameters that are used with an incremental step as, it is mentioned, the. n downTo m corresponds to the range n,m given m