Cascaded and nested if statements in C programming language

Cascaded:

if (condition1)
{
    // do one thing
}
if (condition2)
{
    // do other thing
}

Here, if condition1 is true, one thing will be done. Again, if condition2 is true, other thing will be done too.

Nested:

if (condition1)
{
    // do one thing
    if (condition2)
    {
        // do other thing
    }
}

Here, if condition1 is true, one thing will be done. And, if condition2 is also true, other thing will be done too.

Note that in the latter case, both the conditions need to be true in order for other thing to happen. While in the first case, other thing happens if condition2 is true, irrespective of condition1 being true or false.

Leave a Comment