Nested if else in C

Nested if else a technique to solve the problem in less effort and efficient manner

When there are a series of decisions involved, you may have to use more than one if else statements in nested form. The nested condition means condition within the condition.

This is not a new concept, it is a technique to solve the problem. You can use nested if else statement in three ways.

  • Nested if else within if-block
  • Nested if else within else-block
  • Nested if else within both if-block and else-block

Note: C compiler execute program line by line

1. Nested if else within if-block

In this situation, the nested condition is written within the scope of the main if condition.

Syntax

Example

Output

*: You can see, how you have written nested if else statement to solve the problem. Try to solve some more problem by yourself!

2. Nested if else within else-block

In this situation, the nested condition is written within the scope of the main else.

Syntax

Example

Output

3. Nested if else within both if-block and else-block

In this situation, the nested condition is written within the both i.e within if-block and within else-block.

Syntax

Example

Output

Facts about nested if else statement

  • Any level of nested if else allowed in C.
  • Any number of nested if else allowed in C.
  • Nested if else is a technique to solve the problem.

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)