Number Problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Number Problem

millermandude
How can I create an "if" function so that it's only true if a value is between two different values?
 
Reply | Threaded
Open this post in threaded view
|

Re: Number Problem

Alan G Isaac-2
https://subversion.american.edu/aisaac/notes/netlogo-basics.xhtml#booleans


On 10/13/2017 10:52 AM, [hidden email] [netlogo-users] wrote:
> How can I create an "if" function so that it's only true if a value is between two different values?

Reply | Threaded
Open this post in threaded view
|

Re: Number Problem

cstaelin
In reply to this post by millermandude
You would use the logical operator, "and". E.g.,  if (x >= 1 and x <= 10) [ ... ]
 

Reply | Threaded
Open this post in threaded view
|

Re: Number Problem

Jim Lyons
In reply to this post by millermandude

> On Oct 13, 2017, at 10:52 AM, [hidden email] [netlogo-users] <[hidden email]> wrote:
>
> How can I create an "if" function so that it's only true if a value is between two different values?
>
Start with pseudo-code. If the range values are a and b, you first need to find out which is larger. Then compare your test value, say v, with each as appropriate.

if a < b
        in-range? is true if v > a and v < b
else
        in-range? is true if v > b and v < a

If you consider v to be in range if it is equal to a or b, use <= and >= comparisons instead.

HTH,
Jim