Edwin's profile picture

Edwin Kofler

Language of Sequences in Programming Languages

In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Wikipedia

The mathematical concept of sequences naturally occurs in all useful programming languages. I wanted to review how different programming languages describe the concept.

Syntactically, it’s usually seen in two ways:

for loops. They require:

foreach loops. They require:

Both:

  1. Take a sequence
  2. Perform the iteration

Usually, these concepts are described using the words:

  1. loop, enumerable, list, array, iterable, sequence, collection, vector
  2. loop, enumerate, iterate, go through

Which words should I use?

Word Usage by Programming Languages

Investigating further, I wanted to see how these concepts were described by popular programming languages and sources. Here are the quotes of select sources:

In the Python reference:

The for statement is used to iterate over the elements of a sequence (such as a string, tuple or list) or other iterable object:

In the Python tutorial:

The for statement in Python differs a bit from what you may be used to in C or Pascal. […] Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. For example (no pun intended):

In the ECMAScript Specification:

Information about for is under the header of “iteration statements”.

In Rust by Example:

The for in construct can be used to iterate through an Iterator. One of the easiest ways to create an iterator is to use the range notation a…b. This yields values from a (inclusive) to b (exclusive) in steps of one.

In the Ruby documentation:

The for loop consists of for followed by a variable to contain the iteration argument followed by in and the value to iterate over using each. The do is optional:

In cppreference.com:

Conditionally executes a statement repeatedly, where the statement does not need to manage the loop condition.

In K&R,

Information about for is under the header of “3.5 Loops - While and For”.

Chosen Words

I learned that iterate is used much more frequently than I previously thought. I also realized that I’ve underused the word sequence.

In the context of programming, I’ll share the words that I like the most.

When speaking about a sequence:

When speaking about the action of iterating: