if-else
- Last UpdatedApr 24, 2024
- 1 minute read
The if and if-else statements execute a statement from many possible paths based on the value of a Boolean logical operators statement. The if statement supports multiple conditional else statements and nested if-else statements.
When the if condition is not verified, all else statements defined are evaluated in order. The first else clause whose condition is verified is executed.
After the condition definition (if any), it's possible to start a block of code or a single line without curly brackets, exactly like in C#.
Example code
static void testIf()
{
int a = 3
if (a == 0)
Runtime::Environment.Print("zero");
else if (a == 2)
{
Runtime::Environment.Print("two");
}
else
Runtime::Environment.Print("any");
}
//Output:
//any