C nested if-else

The nested if-else statement is used when a program requires more than one test expression.
We can write if-else statements within another if statement or in the body of else, this is called nested if-else. Nested if-else is a decision making statement.

Syntax of nested if-else statement:

How nested if-else works?

The nested if-else statement has more than one test expression. First of all, if the condition1 is true, it executes the code inside the braces {} just below it. But if the condition1 is false, it checks the respected else-if block i.e. condition2. If the condition2 is true, it executes the code inside the braces {} just below it. This process continues. In this way nested if-else work.

Flowchart of nested if-else statement:

nested if-else

Example:

Output:

Forms of nested if

Following all forms of if, if-else, nested if-else, nested if are valid.
The if statement can be any of the following:

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.