Simple question

This is a discussion on Simple question within the C Programming forums, part of the General Programming Boards category; Hello all those who read this post, Ive decided to learn some C and have run into a problem. I ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    2

    Simple question

    Hello all those who read this post,

    Ive decided to learn some C and have run into a problem.
    I just want to know if the condition in an if statement can be something like the following:

    if (10< i <15) {
    ...

    so far ive only been able to get it to work when it would have only one inequality in it, but is it possible to have 2? and if not, is there some function or something that i can use to make it possible (i need it for a simple program im making right now)?

    Thanks,
    PPeter

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You would write that as
    Code:
    if ((i >10) && (i < 15))
      DoSomethingWonderful();
    The more explicit you are the better your code works.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,017
    do this:
    Code:
    if(10 < i && i < 15)
    The && is the logical and opperator, which yeilds true when both opperands passed to it are true. In this case it's asserting that 10 < i and i < 15. It has a lower precidence than most opperators.

    II is the or operator and it is also common for connecting multi-part criteria like this.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2
    Wow, that was much faster than i thought it would take.
    Thanks CommonTater, and King Mir, this will really help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question
    By ch68813 in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2007, 02:23 PM
  2. simple simple design question
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2005, 11:33 PM
  3. Just a simple question...
    By Lost__Soul in forum C Programming
    Replies: 9
    Last Post: 04-17-2003, 03:07 PM
  4. a simple question
    By DramaKing in forum C Programming
    Replies: 6
    Last Post: 01-07-2002, 05:58 PM
  5. A Simple Question
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 10-26-2001, 05:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21