Search⌘ K
AI Features

Types of Decisional Statements

Explore the key decisional statements in C# including if, else if, else, and nested conditions. Understand how to control program flow based on Boolean expressions to write clear and effective code.

Decision-making is an important part of computer programs. The if, else if, and else statements identify which statement to run based on the Boolean value of an expression.

The if condition

The code in an if statement only executes if the condition is true. In the example below, there’s an if statement with an equality operator of ==.

Example: Print Today is Monday if the value of todaysDay is Monday.

C#
string todaysDay = "Monday";
if (todaysDay == "Monday" )
{
// Code within the curly brackets will execute because Monday equals Monday is TRUE
Console.WriteLine("Today is Monday");
}

In the lesson ...