I’m working on a problem for a programming class that states the following:

Write a for loop in the space below which will add the numbers between 1 and 20.

To me this means the question is looking for the total sum of all the individual numbers from 1 up to 20 (1 + 2 + 3 + 4 + 5 + … + 20).

Is my understanding correct?
Are there any other ways to word this?


Solution 1:

As a programmer, every usage of the between keyword I've seen would define 'between X and Y' as 'greater than or equal to X and less than or equal to Y'

An example would be the BETWEEN comparison operator in MySQL.

I would say your interpretation of 'between 1 and 20' to include the upper and lower bounds (1 and 20) is absolutely correct.

Having said that, it could certainly be more clearly worded. For starters, adding 'the numbers' between 1 and 20, or even 1 and 1.000000001, would be an endless task. They should specify integers at the very least, as well as using a less ambiguous definition of the boundaries such as suggested by @MetaEd (+1).

Solution 2:

In the context of a programming class, it is particularly important to avoid ambiguity about the input. In this case, between could mean the numbers 2 through 19. Perhaps try

… which computes the sum of the numbers 1 through 20.

Solution 3:

I imagine that you're interpreting it the way it was intended, but it should have been worded more clearly. Perhaps "add the integers from 1 through 20, inclusive."