# How to check whether value is in range

**URL:** <https://discourse.processing.org/t/how-to-check-whether-value-is-in-range/27680>\
**Category:** Beginners\
**Created:** [February 9, 2021, 1:43am UTC](https://discourse.processing.org/t/how-to-check-whether-value-is-in-range/27680 "2021-02-09T01:43:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [February 9, 2021, 1:43am UTC](https://discourse.processing.org/t/how-to-check-whether-value-is-in-range/27680/1 "2021-02-09T01:43:52Z")

</div>

I’d like to check whether a value is in a range and then return a color accordingly. This is the first of many if statements:

if(range.between(0,100).contains(value)){  
c = #1a1334;  
}  
else if(Range.between(101,200).contains(value)){  
c = #26294a;  
}  
else if{…}

It says “Cannot find anything named “Range””, so I suppose this function does not exist. What are alternatives?

Thanks!

---

<div class="post-metadata">

**Author:** ![SNICKRS](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SNICKRS](https://discourse.processing.org/u/SNICKRS)\
**Post date:** [February 9, 2021, 3:33am UTC](https://discourse.processing.org/t/how-to-check-whether-value-is-in-range/27680/2 "2021-02-09T03:33:14Z")

</div>

Hello, you can use a `boolean()` to do this easily. Here is an example:

```auto
color c;
boolean inRange(int minValue, int maxValue, int value) {
  if(value >= minValue && value <= maxValue) {
    return true;
  } else {
    return false;
  }
}
for(int i = 0; i < 3; i++) {
  if(i == 1) {
    if(inRange(101, 200)) {
      c = #1a1334;
  }   
} else if(i == 2) {
    if(inRange(201, 255)) {
      c = #26294a;
  }
} else if(i == 0) {
    c = #000000;
  }
}

```

---

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [February 9, 2021, 3:42am UTC](https://discourse.processing.org/t/how-to-check-whether-value-is-in-range/27680/3 "2021-02-09T03:42:56Z")

</div>

So elegant, I love it!
