What is the meaning of "exclusive" and "inclusive" when describing number ranges?

Joel De La Cruz picture Joel De La Cruz · Aug 18, 2016 · Viewed 66.6k times · Source

Simple question but, I see exclusive and inclusive when referring to number ranges.

For example, this is a line from an algorithms book:

The following function prints the powers of 2 from 1 through n (inclusive).

What is meant by this? What makes a number range inclusive or exclusive?

Answer

Rakete1111 picture Rakete1111 · Aug 18, 2016

In Computer Science, inclusive/exclusive doesn't apply to algorithms, but to a number range (more specifically, to the endpoint of the range):

1 through 10 (inclusive)
1 2 3 4 5 6 7 8 9 10

1 through 10 (exclusive)
1 2 3 4 5 6 7 8 9

In mathematics, the 2 ranges above would be:

[1, 10]
[1, 10)

You can remember it easily:

  • Inclusive - Including the last number
  • Exclusive - Excluding the last number