Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 640 Bytes

nested_ifs.md

File metadata and controls

32 lines (27 loc) · 640 Bytes

Nested Ifs

The code inside of the { and } can be anything, including more if statments.

~void main() {
int age = 5; // 👶
if (age < 25) {
    System.out.println("You are too young to rent a car!");
    if (age == 24) {
        System.out.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 help.

if (...) {
    if (...) {
        if (...) {
            if (...) {
                // Seek professional help
            }
        }
    }
}