- Nested selection is an if statement inside an if statement
- If the first if statement is true, it will run the if statement which is nested inside
- Otherwise, it will skip to the "else if" or "else" which is part of that if statement
Pseudocode example:
if a > b then
if b > c then
output “a is the largest”
else
output “c is the largest”
else
if a > c then
output “b is the largest”
else
output “c is the largest”
Python example:
if a > b:
if b > c:
print("a is the largest")
else:
print("c is the largest")
else:
if a > c:
print("b is the largest")
else:
print("c is the largest")
Java example:
if (a > b) {
if (b > c) {
System.out.println("a is the largest");
} else {
System.out.println("c is the largest");
}
} else {
if (a > c) {
System.out.println("b is the largest");
} else {
System.out.println("c is the largest");
}
}
Visual Basic example:
If a > b Then
If b > c Then
Console.WriteLine("a is the largest")
Else
Console.WriteLine("c is the largest")
End If
Else
If a > c Then
Console.WriteLine("b is the largest")
Else
Console.WriteLine("c is the largest")
End If
End If