Adblock breaks this site

if (*** or ***) Then...

Discussion in 'Programming General' started by Cymru, Oct 23, 2008.

  1. Cymru

    Cymru Apprentice
    Banned

    Joined:
    Jan 22, 2007
    Posts:
    693
    Referrals:
    0
    Sythe Gold:
    0
    if (*** or ***) Then...

    Is it possible to add an "or" command so that if one of the options is true, then the command goes through?

    Something like this:

    String animal = "cat";

    if(animal == "cat" or "rabbit")

    Thanks.

    EDIT: FLIP! I did a search right now and found out how to do it with || and &&...
    I can never find out how until I post on sythe...
     
  2. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    if (*** or ***) Then...

    You would use the 'or' operator. C languages don't use keywords for instances like this, they use operators.

    The or operator is simply
    Code:
    ||
    in example,
    Code:
    if(animal=="cat" || animal=="rabbit") DoShit();
    A list of operators for C# can be found on MSDN's website: http://msdn.microsoft.com/en-us/library/6a71f45d(vs.71).aspx
     
  3. Cymru

    Cymru Apprentice
    Banned

    Joined:
    Jan 22, 2007
    Posts:
    693
    Referrals:
    0
    Sythe Gold:
    0
    if (*** or ***) Then...

    Thanks. I got it later as well. I found && as "and" which is helpful.
     
< ...Connection...?????¿¿¿¿ | My first program >


 
 
Adblock breaks this site