Conditional Statements in ASP.NET with example

Conditional Statements in ASP.NET

In asp.net, Conditional Statements allows you to specify which code should be executed depending on which conditions are matched.

Types of Conditional Statements in ASP.NET

There are mainly six types of conditional statements in asp.net, these are:
1. Simple If Statements: Simple If statements are the simplest form of conditional logic. If a certain condition is met, it performs some action. It has the following syntax:

if (condition) {
..................
}

 

2. IfThen Statements: If-Then statement examines the truthfulness of an expression. It has the following syntax:

if condition
then
statement

 

3. If-Then-End If Statements: If there are many statements to execute as a truthful result of the condition, you should write the If-Then-End If Statements. It has the following syntax:

if condition then
statement
end if

 

4. IfThenElse Statements: Whenever you would like to apply an alternate expression in case the condition is false, you can use the If–Then–Else Statement. It has the following syntax:

if condition then
statement
end if

 

5. Case and Switch Statements: A case statement is also called a Select statement, A case statement examines one variable, and you specify the criteria of that variable. It has the following syntax:

select case variable
case option1
statements
case Else
statements
end select

 

If we call it a value that is not checked by the first argument, the function produces a null value. So, we use the Switch Statements. It has the following syntax:

switch(condition1, statement1, condition2, statement2)

 

6. Choose Statements: When the Choose statement is called, if the first argument has a value of 1, then the second argument is validated. If the first argument has a value of 2, then the third argument is validated. It has the following syntax:

Choose(argument1, "argument2", "argument3")