Search code examples
algorithmterminologydefinition

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


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?


Solution

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

    This means that the function will compute 2^i where i = 1, 2, ..., n, in other words, i can have values from 1 up to and including the value n. i.e n is Included in Inclusive

    If, on the other hand, your book had said:

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

    This would mean that i = 1, 2, ..., n-1, i.e. i can take values up to n-1, but not including, n, which means i = n-1 is the highest value it could have.i.e n is excluded in exclusive.