# Is the number within a range?

**URL:** <https://forum.kirupa.com/t/is-the-number-within-a-range/305716>\
**Category:** flash\
**Created:** [March 2, 2010, 3:39pm UTC](https://forum.kirupa.com/t/is-the-number-within-a-range/305716 "2010-03-02T15:39:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdulberg](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jdulberg](https://forum.kirupa.com/u/jdulberg)\
**Post date:** [March 2, 2010, 3:39pm UTC](https://forum.kirupa.com/t/is-the-number-within-a-range/305716/1 "2010-03-02T15:39:44Z")

</div>

Hello,

I have a slider where I check the current value to see if it’s within various number ranges. I’m basically running the same comparison over and over for 14 range sets. Is there a way to not have to hard code each one?

The snippet below is hard coded 14 times with incrementing boxes[x] values. boxes[x] is a predefined array:

```auto

if (sliderval >= boxes[1].position && sliderval < boxes[2].position) {
 //do 1st code
}
else if (sliderval >= boxes[2].position && sliderval < boxes[3].position) {
 //do 2nd code
}
//etc...

```

These ranges are checked as the user moves the slider button.

Any suggestions would be great!

Thanks,  
Jason
