Beginner if/switch question

• 04-01-2009
GuitarNinja
Beginner if/switch question
Hi, I've been wondering, what syntax would you use to check an if or switch statement against a range of values, instead of just one? For example, how would I check to see if an entered value is between, say, 5 and 25 instead of just checking each number individually? I'm still really new to everything and I've been curious of this for a while, but haven't been able to figure it out. Any help would be greatly appreciated!
• 04-01-2009
brewbuck
Quote:

Originally Posted by GuitarNinja
Hi, I've been wondering, what syntax would you use to check an if or switch statement against a range of values, instead of just one? For example, how would I check to see if an entered value is between, say, 5 and 25 instead of just checking each number individually? I'm still really new to everything and I've been curious of this for a while, but haven't been able to figure it out. Any help would be greatly appreciated!

If a number is greater than or equal to 5, and less than or equal to 25, then it's between 5 and 25.
• 04-01-2009
prog-bman
Use the || and &&
Code:

`if(value >= 5 && value <= 25){}`
• 04-01-2009
GuitarNinja
Ok, that makes sense now, I think you answered it perfectly. Thanks guys!