Nested if statement in C Langauge
Nested if statement contains one if statement block taken inside another if statement. The syntax of nested if statement is:
Initially Condition-Expression1 is checked. If it is true, Condition-Expression2 is checked. If it is also true, Statements1 is executed otherwise Statements2 is executed. If Condition–Expression1 as false, Condition-Expression3 is checked. If it is true, Statements3 will be executed. otherwise Statements4 will be executed.
Statements1, Statements2, Statements3 and Statements4 are set of valid statements of C Language.
printf(“\nEnter a value:=”);
printf(“\nBetween 100 and 200 “);
printf(“\nSmaller than 100”);
|Enter a value:=130
Between 100 and 200
In the above program, a has been entered 130.
if(a>=100) is true so if(a<=200) is checked. It is also true so printf(“\nBetween 100 and 200”) is executed.