I am having a problem with IF statement in c#

So i am having problems with an if statement.

    if (Who == "X")
        if (Process == 1)
            HorBotX = +1;
        else
                if (Process == -1)
            HorBotX += -1;
        else
        if (Who == "O") //the next immediate statement of code will be skipped......Why?
            Debug.Log("O succeeded"); /*this line will be skipped. if debug wasn't there, it would be the next IF that would be skipped */
            if (Process == 1)
                HorBotO += +1;
            else
                        if (Process == -1)
                HorBotO += -1;

    Debug.Log("HorBot:  " + "X: " + HorBotX + " And " + "O: " + HorBotO);

i am curious as to why this is. now i have worked Around this, but still, it is unexplained to me. Help?

This feature of if/else is standard across all programming languages, not just C#. The else goes with the innermost if, so they don’t pair up with the way your code suggests you expected.

The way to avoid these problems is to avoid nested if/else; and where you really want to use nested if/else insert braces to make your intent clear. If I reformat the code like this you can see how that works.

 if (Who == "X") {
     if (Process == 1) HorBotX = +1;
     else if (Process == -1) HorBotX += -1;
 } else if (Who == "O") {
      if (Process == 1) HorBotO += +1;
      else if (Process == -1) HorBotO += -1;
 }

Some people would have you add braces for everything and give dumb logic to support it, but you do need a minimum level of braces to avoid problems like this.