TutorialStudyMite

Nested if else in c with program

Sstudymite1 min read
Beginner friendly

Track completion, mastery, and revision.

Nested if-else

A nested if statement is a type of control flow statement that allows you to include an additional if or else statement within an existing if or else statement. This allows you to perform multiple checks on a single condition or to create more complex control flow logic in your code.

The nested if statement looks like this:

if (condition) {
    // Do something if the condition is true
    if (condition) {
        // Do something else if the second condition is also true
        executeThisStatement;
    }
}

Example :

#include <stdio.h>

int main() {
    int a = 20, b = 30;
    if (a > b) {
        printf("a is greater than b");
    } else if (a < b) {
        printf("a is less than b");
    } else {
        printf("a is equal to b");
    }
    return 0;
}

Output :

a is less than b

Finished reading?

Was this helpful?

Your feedback shapes better tutorials for everyone.