What are decision making statements in C#?


Decision making statements requires the programmer to specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

The following are the types of decision making statements −

Sr.NoStatement & Description
1if statement
An if statement consists of a boolean expression followed by one or more statements.
2if...else statement
An if statement can be followed by an optional else statement, which executes when the boolean expression is false.
3nested if statements
You can use one if or else if statement inside another if or else if statement(s).
4switch statement
A switch statement allows a variable to be tested for equality against a list of values.
5nested switch statements
You can use one switch statement inside another switch statement(s).

Let us see an example of if-else decision making statement in C#.

Example

 Live Demo

using System;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         int a = 50;

         if (a < 10) {
            Console.WriteLine("a is less than 10");
         } else {
            Console.WriteLine("a is not less than 10");
         }
         Console.WriteLine("a = {0}", a);
         Console.ReadLine();
      }
   }
}

Output

a is not less than 10
a = 50

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 20-Jun-2020

126 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements