Conditional Branching


If Statement

If - Else

if (bValue == true) 
{
   sVariable1 = "text";
}
else
{
   sVariable2 = "text";
}
if (bValue == true)
{
   sVariable1 = "text";
}

Switch - Case

Switch - Case

switch (Temp) 
{
   case 0:
        r += 1;
        break;
   case "green"
        r++;
        break;
   default:
      break;
}

Conditional Operator

Also known as the Tenary Operator or Conditional Operator.

if (bValue == true) ? sVariable1 = "text" : sVariable2 = "text"; 

This is the short form of the if-else condition.
If the condition evaluates to true then it will execute the first statement after ?, otherwise the second statement after : will be executed.

if (bValue == true) ? sVariable1 = "text" : sVariable2 = "text"; 


Nested

Nested ternary operators are possible by including a conditional expression as a second statement.
The ternary operator is right-associative.
The expression a ? b : c ? d : e is evaluated as a ? b : (c ? d : e) and not evaluated as (a ? b : c) ? d : e.


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext