The if Statement
One of the single most important statements in every programming language is the if statement. Being able to set up conditional blocks of code is a fundamental principal of writing software. In C#, the if statement is very simple to use. If you have already used another programming language, chances are that you can use the if statement of C# straight away. In any case, read on to see how it’s used. The if statement needs a boolean result, that is, true or false. In some programming languages, several datatypes can be automatically converted into booleans, but in C#, you have to specifically make the result boolean. For instance, you can’t use if(number), but you can compare number to something, to generate a true or false, like we do later on.
In the previous chapter we looked at variables, so we will expand on one of the examples to see how conditional logic can be used.
The Code:

The Output of Your Program:

Relational Operators
Use relational operators to evaluate conditions. In addition to the less than (<) and greater than (>) operators, the following operators are available:

The Code:

The Output of Your Code:

The else Clause
An optional else clause can be specified to execute a block of code when the condition in the if statement evaluates to false.
The Code:

The Output of Your Program:

Nested if Statements
You can also include, or nest, if statements within another if statement.
The Code:

The Output of Your Program:

The if-else if Statement
The if-else if statement can used to decide three or more condition.
The Code:

The Output of Your Program:



