Nested Ifs
The code inside of the { and } can be anything, including more if statments.
void main() {
int age = 5; // 👶
if (age < 25) {
IO.println("You are too young to rent a car!");
if (age == 24) {
IO.println("(but it was close)");
}
}
}
When an if is inside another if we say that it is "nested".
If you find yourself nesting more than a few ifs that might be a sign that
you should reach out for help1.
if (...) {
if (...) {
if (...) {
if (...) {
// Seek professional help
}
}
}
}
1
Or a sign that you should keep reading. There are things I will show you that can help you avoid this - like "methods."