Locked lesson.
About this lesson
In this lesson, we learn how to use "else if" within an If/Else statement.
Exercise files
Download this lesson’s related exercise files.
34 - Logic If else if.docx61 KB 34 - Logic If else if SOLUTION.docx
58.8 KB
Quick reference
Logic: If/else if
If else if allows you to test for more than one condition in your if statement.
When to use
Use this when you need to test for more than one condition in your if statement.
Instructions
int a,b;
a = 20;
b = 19;
if (a>b)
{
Console.WriteLine($"{a} is Greater than {b}");
}
else if (a == b)
{
Console.WriteLine($"{a} is Equal To {b}");
}
else
{
Console.WriteLine($"{a} is Not Greater than {b}");
}
Hints & tips
- Allows you to test more than one condition in your if statement.
Lesson notes are only available for subscribers.