Results 1 to 5 of 5
  1. #1
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    562
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default Syntax question: checking a variable for multiple values [answered]

    Is there a shorthand way to check one variable for multiple values?

    For example:
    Code:
    if (Value1 != x && Value1 != y)
    I find myself wanting to shorten that, since I am checking the same value, I want to write it out as "value != (x or y)."
    Especially since when I end up checking the same value for multiple entries I usually have some long-A variable names.
    Is there a shorthand way to write that?
    Last edited by marscaleb; 05-26-2012 at 07:10 PM.
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  2. #2
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Posts
    484

    Default

    marscaleb
    No. Other version is
    Code:
    if(!(value1==x||value1==y))
    In some cases switch-case may help too.
    Last edited by rquester; 05-26-2012 at 07:02 PM.

  3. #3

  4. #4
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    562
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default

    Yeah I thought about switch-case but that wouldn't make my code cleaner and shorter unless I has a lot of possibilities to check for.

    Thanks for the prompt answer!
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  5. #5
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,261

    Default

    Quote Originally Posted by marscaleb View Post
    Especially since when I end up checking the same value for multiple entries I usually have some long-A variable names.
    Is there a shorthand way to write that?
    You can create a local copy if the name is long.

    Code:
    local int a;
    a = LongVariableName;
    
    if(a == 1 || a == 5 ....
    Just remember you can't affect the original variable by writing to it - unless it's an out parameter of a function.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.