Sequence(start, end, step)

Creates a list of numbers from «start» to «end» by equal increments (or decrements) of «step». You may omit «step», which defaults to 1. «step» must be a positive number. «start», «end», and «step» must be deterministic scalar numbers, not arrays and not uncertain. See Expressions that don't array-abstract.

You can also select this function using the Sequence option from the expr menu.

The expression m..n using the Sequence Operator ".." is equivalent to Sequence(m, n, 1).


Sequence(1, 5) → [1, 2, 3, 4, 5]

Chapter11 77.jpg

The parameter value for «end» is greater than the value for «start», so the sequence is increasing.

Optional parameters


Normally, if «start» is larger than «end», and «step» is positive, the sequence decrements by «step». As a result of this convention, a sequence will always have at least one element.

There are cases where a strict sequence is desired, such that the sequence proceeds from «start» in increments of «step», according to the sign of «step». When «step» proceeds in the direction away from «end», then a zero-length sequence results. For example, in a For..Do loop, you may want zero iterations when «end» is less than «start». Specifying the optional parameter «strict» as true obtains a strict Sequence, for example:

Sequence(x1, x2, strict: True)

When «strict» is specified as True, the step may be negative, and must be negative to obtain a decreasing sequence. For example:

Sequence(5, 1, strict: True) → []
Sequence(5, 1, -2, strict: True) → [5, 3, 1]


You can use Sequence to create a sequence of successive days, hours, or 15 minute intervals, the first day of each week, month, or year, and so on. You specify the units with the optional «dateUnit» parameter. For example, this generates dates at quarterly (3-month) intervals:

Sequence(MakeDate(2015, 1, 1), MakeDate(2016, 6, 31), 1, dateUnit: "Q") →
[1-Jan-2015, 1-Apr-2015, 1-Jul-2015, 1-Oct-2015, 1-Jan-2016, 1-Apr-2016]

These are the characters defining each date and time unit:

  • Years: 'Y'
  • Quarters: 'Q'
  • Months: 'M'
  • Days: 'D' (the default when «dateUnit» is omitted)
  • Weekdays: 'WD'
  • Hours: 'h'
  • Minutes: 'm'
  • Seconds: 's'

Details & More Examples

Character Sequences

You can specify «start» and «end» each as a character, and it will generate a sequence of characters in ASCII order:

Sequence('T', 'f') →
['T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f']
Sequence('!', '@') →
['!', '""', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@']

Spreadsheet Column Name Sequences

You can also use Sequence to generate a sequence of spreadsheet column names -- which go from 'A' to 'Z', then 'AA' to 'AZ', 'BA' to 'BZ', ... 'ZA' to 'ZZ', then 'AAA'..'ZZZ', 'AAAA'..'ZZZZ', etc., up to six letters total. In this case, «start» and «end» must contain one or more letters, either all uppercase or all lowercase:

Sequence('W', 'AF') →
['W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF']


If «start» is greater than «end», the sequence is decreasing:

Sequence(5, 1) → [5, 4, 3, 2, 1]

If «start» and «end» are not integers, and you omit «step», the function rounds them:

Sequence(1.2, 4.8) → [1, 2, 3, 4, 5]

If you specify «step», the function can create non-integer values:

Sequence(0.5, 2.5, 0.5) → [0.5, 1, 1.5, 2, 2.5]

See Also


You are not allowed to post comments.