Ranges
Defining a Range
Use a range in SenseTalk to indicate a range of values. A range is specified by giving a start value and an end value, using either a double-dot operator (two periods in a row, ..
) or the word to
between the two values.
Syntax:
{from} startValue [ to | .. ] endValue { [{step{ping}} {down} by | step] stepvalue }
Example:
put 1 to 100 into firstHundred
set validRange to 100..200
A range may optionally include a step value, using the word by
or step
or step by
(the use of step values is described in "Using a Range to Generate a List", below):
Example:
put 1 to 99 step by 2 into oddNumbers
set evenNumbers to 0..100 by 2
Simple Uses of Ranges
In its simplest uses, a range specifies two values. Access the start
and end
values directly, as properties of the range:
Example:
set myRange to 10 .. 20 -- 10 to 20
put myRange.start --> 10
put myRange's end --> 20
add 15 to the end of myRange
put myRange --> 10 to 35
Use the is within
operator to test if another value falls within the range:
Example:
set myRange to 10 .. 20
put 13 is within myRange --> True
put 18.975 is within myRange --> True
put 9.2 is within myRange --> False