Open In App

Nested if in C++

Last Updated : 06 Feb, 2023
Comments
Improve
Suggest changes
24 Likes
Like
Report

If is a type of condition checking in which a condition turns out to be true a block of statements is executed.

Syntax:

// if base_condition is true
// every inside the { } block will be executed
if (base_condition)
{
    statement 1...............
    statement 2 ..............
}

Example


Output
True

What is Nested If?

When a number of if blocks are present one after another with the same scope (the same scope means under one { } block), then that condition is termed as a Nested if condition. If the first condition is True, we go into the next if condition and the subsequent condition is checked until we get a false condition, and the checking stops.

Syntax:

// if base_condition is true control goes to base_condition1
if ( base_condition) 
{
    // if base_condition is true control goes to base_condition2
    if(base_condition1) 
    {
        if(base_condition2) 
            ..........................
        ..........................
    }
}
Nested if in C++
 

Example 1:


Output
 a is the largest 

Example 2:


Output
Sandeep Sir is Great!!

Example 3:


Output
gfg

Example 4:


Output
 No nested if condition is executed 
 

Time complexity: O(1).

Auxiliary space: O(1).


Similar Reads