C# Decision Making

C# language possessed such decision-making capabilities and supports the following C# Decision-Making statements:

    1. if statement
    2. switch statement
    3. conditional operator statement

if statement:

The if statement is a powerful decision-making statement and it is used to control the flow of execution of statements. It is a two-way decision statement and it is used in conjunction with an expression. It has the following syntax:

if(expression)
{
  statement block;
}
statement-x;

It allows the computer to evaluate the expression first and then, depending on whether the value of the expression is true or false. It transfers the control to a particular statement. The statement block is a single statement or a group of statements. If the expression is true, the statement block will be executed, otherwise, the statement block will be skipped and the execution will jump to the statement-x.

if-else statement:

The if-else statement is an extension of the simple if statement. If the boolean expression is true, the true-block statements will be executed, otherwise, false-block statements will be executed and the control is transferred subsequently to the statement-x.

It has the following syntax:

if(boolean-expression)
{
 True-block statements;
}
else
{
 False-block statements;
}
statement-x;

switch statement:

Switch is a built-in multiway decision statement. The switch statement tests the value of a given variable or expression against a list of case values and when a match is found, a block of statements associated with that case is executed.

switch(expression)
{
 case value-1:
 block-1
 break;
 case value-2:
 block-2
 break;
 ......
 .....
default:
 default-block
 break;
}
statement-x;