Not equals to (number to number)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 14
- Joined: Tue Feb 14, 2012 5:04 pm
Not equals to (number to number)
Hi, I was wondering is it possible to make variable comparison to a range of numbers in a simple way, something like if X is not equal to 16 to 20 (which are 16,17,18,19,20) then do something. Would be so nice
Re: Not equals to (number to number)
You can just do something like this:
Meaning it will be true as long as it is not between these two numbers. Seems a bit silly to add a special function for this.
Code: Select all
if x > 16 or x < 20 then
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Not equals to (number to number)
I usually put the two conditions in a way that makes the numbers increase, from lower to upper:
if you *really* need a function, this should do:
Usage:
Code: Select all
if min <= x and x <= max then ...
Code: Select all
function between(x,min,max)
return min <= x and x <= max
end
Code: Select all
if between(x,16,20) then ...
When I write def I mean function.
Re: Not equals to (number to number)
Wont that be trur if x is larger than 16 OR less than 20 meaning that anything would return trueCamewel wrote:You can just do something like this:Meaning it will be true as long as it is not between these two numbers. Seems a bit silly to add a special function for this.Code: Select all
if x > 16 or x < 20 then
Eg. 5<20 therefore continue if statement
Your screen is very zoomed in...
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Not equals to (number to number)
True.mickeyjm wrote: Wont that be trur if x is larger than 16 OR less than 20 meaning that anything would return true
Eg. 5<20 therefore continue if statement
Kurosuke needs beta testers
Re: Not equals to (number to number)
Oh, you know what I meant.
Code: Select all
if x < 16 or x > 20 then
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Not equals to (number to number)
Oh, I read this incorrectly. OP wanted to check that x is not in the range. Well, once you have a function, doing the contrary is easy:
If you want to write the whole code with no functions, I sill think it helps to have the numbers in order. I'd do something like this:
But for the negation, I think that "not between" is more clear.
Code: Select all
if not between(x,16,20) then ...
Code: Select all
if min > x or x > max then ...
When I write def I mean function.
- trubblegum
- Party member
- Posts: 192
- Joined: Wed Feb 22, 2012 10:40 pm
Re: Not equals to (number to number)
Actually, what OP specified was not inrange(x, 16, 20) - between(x, 16, 20) implies exclusion of the range limits, 16 and 20.
So :You were closer the first time
So :
Code: Select all
function inrange(x, lower, upper)
return x >= lower and x <= upper
end
if not inrange(x, 16, 20) then end
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 11 guests