KnowledgeBoat Logo

Computer Applications

Explain the following statement with their constructs:

nested if

Java Conditional Stmts

121 Likes

Answer

We can write an if-else statement within another if-else statement. We call this nested if. It has the following syntax:

if (condition 1) {
    if (condition 2) {
        Statement a;
        Statement b;
        ..
    }
    else {
        Statement c;
        Statement d;
        ..
    }
}
else {
    if (condition 3) {
        Statement e;
        Statement f;
        ..
    }
    else {
        Statement g;
        Statement h;
        ..
    }
}

Answered By

78 Likes


Related Questions