If the expression in the parenthesis is evaluated to be true, then the Console.WriteLine("The boolean flag is set to ture."); statement is executed. After executing the if statement, control is transferred to the next statement. The else is not executed in this example.
If you wish to execute more than one statement, multiple statements can be conditionally executed by including them into blocks using {} as in the example above.
The statement(s) to be executed upon testing the condition can be of any kind, including another if statement nested into the original if statement. In nested if statements, the else clause belongs to the last if that does not have a corresponding else. For example:
if (x > 10)
if (y > 20)
Console.Write("Statement_1");
else
Console.Write("Statement_2");
In this example, Statement_2 will be displayed if the condition (y > 20) evaluates to false. However, if you want to associate Statement_2 with the condition (x >10), use braces:
if (x > 10)
{
if (y > 20)
Console.Write("Statement_1");
}
else
Console.Write("Statement_2");
In this case, Statement_2 will be displayed if the condition (x > 10) evaluates to false