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

前端 未结 3 1686
野趣味
野趣味 2021-02-01 05:23

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

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

The follo

3条回答
  •  Happy的楠姐
    2021-02-01 05:34

    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

提交回复
热议问题