Selection Statements

  • A selection statement is a control statement that allows for choosing between two or more execution paths in a program on the basis of some condition.
  • C#.Net includes one-way, two-way and n-way (multiple) selectors.
    • An if statement with no else is a one way selector.
    • An if..else statement is a two way selector.
    • if..elseif..else, nested if and switch statements are n-way selectors.
  • C#.Net includes the following selection statements:
StatementDescription

if statement

An if statement consists of a boolean expression followed by one or more statements.

If..Then..Else statement

An if statement can be followed by an optional else statement, which executes when the boolean expression is false.

If..Then..Else if..Else statement

An if statement can be followed by an optional else statement, which executes when the boolean expression is false.

Nested If statement

You can use one if or else if statement inside another if or else if statement(s).

Select….Case statement

A switch statement allows a variable to be tested for equality against a list of values.