Thread: Anyway to shorten this if statement?

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    269

    Anyway to shorten this if statement?

    Code:
     if(tag == TAG_START | tag == TAG_VOTE | tag == TAG_VOTE_NO ........ etc etc)

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    A switch might be appropriate.

    By the way, using || with short circuit evaluation may be better than using | here.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by laserlight View Post
    A switch might be appropriate.

    By the way, using || with short circuit evaluation may be better than using | here.
    Not only that... it will behave differently too.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by dayalsoap View Post
    Code:
     if(tag == TAG_START | tag == TAG_VOTE | tag == TAG_VOTE_NO ........ etc etc)
    What are you trying to do?
    Show code if you can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help to shorten my code.
    By hugoguan in forum C Programming
    Replies: 7
    Last Post: 12-01-2010, 02:19 AM
  2. [C] How to shorten this program?
    By milky in forum C Programming
    Replies: 13
    Last Post: 11-07-2009, 10:44 AM
  3. Need to simplify/shorten this code. Help.
    By Lonck in forum C++ Programming
    Replies: 5
    Last Post: 11-08-2007, 04:23 AM
  4. shorten the string
    By beon in forum C Programming
    Replies: 28
    Last Post: 11-14-2006, 12:56 AM
  5. Shorten Statements are WRONG?!
    By RoD in forum C++ Programming
    Replies: 29
    Last Post: 11-01-2002, 06:05 AM