# Comparing an number to others in a list

Hi -
This is probably simple, so please forgive my ignorance. If I have a variable that is storing a number -

`````` set theNum to 46
``````

-how can I compare that to a range of numbers? For example, I want to test if 46 exists within a range from 30 to 50 . The range of numbers 30 through 50 exists in another variable. I’m guessing this list of numbers would look similar to the shortened version below.

``````set theList to (30, 31, 32, 33, 46, 50)
``````

Would it be as simple as:

``````if theNum exists within theList then
--do something
end if
``````

Is there a way to make my list more concise without having to spell out each number to check against?

Thanks!

You’re close but getting too fancy:

``````set theNum to 46
set theList to {30, 31, 32, 33, 46, 50}
if theNum is in theList then --or if  theList contains theNum then
return true
else
return false
end if
``````

Jon

Ah! Very cool. Thanks!

Any suggestions for making theList variable a little easier? Pretty sure I can’t do

``````set theList to (30 - 50)
``````

because that would be a mathematical operation. Yet, visually, that’s how I’m inclined to think of a range of numbers. I just wondered if there’s something cleaner than just listing every number I want to check against.

Thanks again!

I don’t know how to specify a range like you are describing, but you could potentially build your list easier.

``````set rangeList to {}
repeat with aNum from 10 to 30
copy aNum to end of rangeList
end repeat
``````

``````if theNum >= 30 and theNum <= 50 then