C range of value checking clarification

Discussion in 'C Programming' started by satya123, Mar 15, 2011.

  1. satya123

    satya123

    Joined:
    Jul 6, 2010
    Messages:
    6
    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
     
    satya123, Mar 15, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Summercoolness@gmail.com

    range() is not the best way to check range?

    Summercoolness@gmail.com, Jul 18, 2006, in forum: Python
    Replies:
    46
    Views:
    1,000
    Antoon Pardon
    Jul 25, 2006
  2. Lambda
    Replies:
    2
    Views:
    425
    James Kanze
    Jul 16, 2008
  3. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    171
    Tomoyuki Kosimizu
    Nov 27, 2003
  4. David Bird
    Replies:
    1
    Views:
    246
    Tiago Macedo
    Jun 23, 2008
  5. Joey Zhou
    Replies:
    5
    Views:
    251
    Joey Zhou
    Apr 15, 2011
Loading...

Share This Page