Professional Documents
Culture Documents
C# Mhabad
C# Mhabad
C# Mhabad
2022-2021
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.
If <condition>
Statements;
else if<condition>
4
Statements;
else
Default statements
else
Default statements;
if (Department.ToUpper() == "IT" ||
Department.ToUpper() == "CSC")
5
int Percentage = int.Parse(Console.ReadLine());
else
else
6
}
else
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