Inclusive ranges can be specified using 'to':
Range can specify a step for an increment:
Range can specify to include its upper bound value:
Ranges can be specified using 'until':
A range does not include its upper bound, even in a step increment:
A Range is an ordered sequence of integers that are equally spaced apart.
A Range is an ordered sequence of integers that are equally spaced apart. For example, "1, 2, 3" is a range, as is "5, 8, 11, 14". To create a range in Scala, use the predefined methods to
and by
. 1 to 3
generates Range(1, 2, 3)
and 5 to 14 by 3
generates Range(5, 8, 11, 14)
.
If you want to create a range that is exclusive of its upper limit, then use the convenience method until
instead of to
: 1 until 3
generates Range(1, 2)
.
Ranges are represented in constant space, because they can be defined by just three numbers: their start, their end, and the stepping value. Because of this representation, most operations on ranges are extremely fast.
A range's upper bound is not inclusive:
The parameterless execute method has been deprecated and will be removed in a future version of ScalaTest. Please invoke execute with empty parens instead: execute().
The trap method is no longer needed for demos in the REPL, which now abreviates stack traces, and will be removed in a future version of ScalaTest