Nested If or If-Else Statement in Computer Programming: C Language

In any computer programming, a variation of if or if-else statement is known as nested if statement. When an if or if-else statement is used within another if or if-else statement then this statement is called nested if statement. When an action has to be performed based on many decisions, then this statement is used. So, it is called multi-way decision statement. There can be many variations of nested if statement. A sample is given below:

if(condition){ if or if-else statement}else { if or if-else statement}

In this statement the conditions are evaluated from the top to bottom. If the outermost condition i.e., condition1 is true the statement(s) associated with this condition are executed as the inner if part is executed here. If condition2 is true the statement associated with this condition are executed otherwise the else (condition2’s false part) part’s statement(s) are executed. If the condition1 of outermost if statement is false then, else part of this if statements are executed, as shown in the above syntax.

In the above example the if-else statement is inside if statement, hence the above statement is called the nested if statement. Here, if salary >= 25000 and age is less than or equal to 65, then the output is "Increment in salary 25%". If salary is >= 25000 and age is above 65 then the output will be "Increment in salary 24%".