How to compare a variable with two values ​​at the same time?

I need to improve this statement by correcting it or reducing it

if (0 <= age <= 100) // age is between 0 and 100) 

I am completely confused by the fact that I spent 20 minutes on the question. It seems very simple, but the only revision I could think of is

 if (0 <= age && age <= 100) 

and that doesn't seem right. Did I just miss something obvious? Can someone help me?

thanks

+4
source share
1 answer

Your version is correct. if (0 <= age && age <= 100) is the right way to do this. This is really not an easy way.

+7
source

All Articles