Nested if statement in C Langauge
In nested if statement, one if statement block is enclosed within another if statement block. The syntax of nested if statement is:
Initially Condition-1 is checked. If it is true, Condition-2 is checked. If Condition-2 is also true, Statement-Block-1 is executed. If Condition-2 is false, Statement-Block-2 is executed. If Condition-1 as false, Condition-3 is checked. If Condition-3 is true, Statement-Block-3 will be executed. if Condition3 is false, Statement-Block-4 will be executed.
|Program to demonstrate the use of nested if statement.|
printf(“\nEnter a value:=”);
printf(“\nValue is between 0 & 5”);
printf(“\nValue is larger than 5”);
printf(“\nValue is smaller than 0”);
|Enter a value:=3|
Value is between 0 & 5
In the above program, a has been entered 6.
Condition if(a>=0) is true, So condition if(a<=10) is checked. This condition is also true so printf(“\nValue is between 0 & 10”) gets executed.