C range of value checking clarification

Joined
Jul 6, 2010
Messages
6
Reaction score
0
Hi all,

I used the following C code to check for a value in the expected range

float var;
range1 to range10 are float values,

if(range1< var < range2)
statement1;
else if(range2 < var < range3 )
statement2;
else if(range3 < var < range4)
statement3;
-
-

else if(range9 < var < range10)
statement10;

I found that the compiler is executing the first statement and removing all the else if statements saying the warning " Removed Dead assignment". Could somebody tell me whether the above range checking code is valid or not?

I replaced the above code with the following

if( (range1< var) && (var < range2))
statement1;
else if( (range2< var) && (var < range3) )
statement2;
else if( (range3< var) && (var < range4))
statement3;
-
-

else if( (range9< var) && (var < range10))
statement10;

then it is working properly.

could somebody explain me this?

Thanks
Satya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top