C# Mhabad

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Duhok Polytechnic University

Shekhan / Technical Institute


Is Department

2022-2021

Prepared By : Mhabad Jamal MohammedHassan

Stage : First / Second Semester

Subject : Principle Of Programming

Report Title: Nested If

Supervised by : Mr.Awf Abdulrahman

Date : 2022/4/9
 Contents …
 Introduction … 3
 Nested If – else … 4
 The syntax of the C# Nested If Statement … 4
 Nested If Statement Example … 5
 Resources… 8

2
 Introduction
Nested If in C Programming is placing If Statement inside
another IF Statement. Nested If in C is helpful if you want to
check the condition inside a condtion. If Else Statement prints
different statements based on the expression result (TRUE,
FALSE). Sometimes we have to check even further when the
condition is TRUE. In these situations, we can use these C
Nested IF statements, but be careful while using it.

3
 nested if-else
An if...else statement can exist within another if...else statement.
Such statements are called nested if...else statement.Nested if
statements are generally used when we have to test one
condition followed by another. In a nested if statement, if the
outer if statement returns true, it enters the body to check the
inner if statement.

 The syntax of the C# Nested If Statement


If <condition>

If <condition>

Statements;

else if<condition>

4
Statements;

else

Default statements

else

Default statements;

 Nested If Statement Example


1)
Console.WriteLine("Enter your Department");

string Department = (Console.ReadLine());

if (Department.ToUpper() == "IT" ||
Department.ToUpper() == "CSC")

Console.WriteLine("Enter your Percentage");

5
int Percentage = int.Parse(Console.ReadLine());

if (Percentage >= 60)

Console.WriteLine("Enter your age");

int Age = int.Parse(Console.ReadLine());

if (Age < 50)

Console.WriteLine("You are eligible for this


post");

else

Console.WriteLine("Your age is not suitable for


the requirement");

else

Console.WriteLine("Your Percentage is not suitable


for the requirement");

6
}

else

Console.WriteLine("Your qualification is not suitable


for the requircement");

2)
int x = 5, y = 20;
if (x > y)
{
if (x >= 10)
{
Console.WriteLine("x value greater than or equal to 10");
}
else
{
Console.WriteLine("x value less than 10");
}
}
else
{
if (y <= 20)
{
Console.WriteLine("y value less than or equal to 20");
}
else
{
Console.WriteLine("y value greater than 20");
}
}
Console.WriteLine("Press Enter Key to Exit..");
Console.ReadLine();
}

7
 Resources…

https://www.tutorialgateway.org/csharp-nested-if-statement/

https://www.tutlane.com/tutorial/csharp/csharp-nested-if-else-
statements-with-examples

https://www.decodejava.com/csharp-nested-if-statement.htm

You might also like