C# Decision Making Statements

In Decision making, one or more conditions are evaluated by the program. The following are the decision-making statements in C#:

  • if
  • if…else
  • if…elseif..else

The if statement in C#

Under if, the statement executes if the condition is true. The syntax is as follows:

Let us see an example of the if statement in C#:

Output

The if…else statement in C#

Under if-else statement, the first statement executes if the condition is true, else statement 2 executes.

The syntax is as follows:

Let us see an example of the if…else statement in C#:

Output

The if…elseif…else statement in C#

The if-else if-else executes and whichever condition is true, the associated statement executes. If none of them is true, then else executes.

The syntax is as follows:

Let us see an example of the if…elseif…else statement in C#:

Output

C# - Loops
C# Data Types
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading