Decision Making Statements – Introduction

October13, 2017
by admin

In general, many times in our life we have to take decisions based on the criteria. If the criteria are matched with the required specifications, then we go ahead to do the thing in one way. If it doesn’t meet the specification or prerequisites, then we do the thing in other way or we don’t do it at all.

For example, for an exam, various grades are predefined based on the range of the marks. Suppose the excellent grade is predefined for marks more than 80, then the students who got more than 80 marks have an excellent grade. When we do the coding in C#, many times we have to take decisions which code should be executed or whether the code is going to execute or not based on some predefined requirements of the flow. That’s where we have to use decision-making statements.

In decision-making statements, we are taking the decision based on the result of the condition or conditions. The result is boolean i. e. it is either true or false. If the condition returns true, then we execute the specific code defined within the code block for that specific condition. If the condition returns false, then we don’t execute that code for that condition and move to the next code statements. To understand this have a look at the syntax of one of the decision-making statements ‘If’.


  if(<condition>)
  {
    // code to be executed only if condition return true
  }

Here is the condition is any expression that returns a boolean value (either true or false).

The decision-making statements have two broad categories and each category may have sub-variation.

1. if statements

  • If statement
  • If…else statement
  • If…else if statement

2. switch statement

Apart from these two statements, another operator is available in C# for decision-making, a turnery operator (?:).

Let us go through each statement with code examples in upcoming posts.

C# Fundamentals