Nested if-else Statements
In this kind of statement, a number of logical conditions are tested for taking decisions. Here, the if keyword followed by an expression is evaluated. If it is true, the compiler executes the block following the if condition; otherwise, it skips this block and executes the else block. It uses the if statement nested inside an if-else statement, which is nested inside another if-else statement. This kind of nesting can be limitless. The syntax of a simple nested if-else statement is shown in Figure.
The nested if-else
The flowchart for nesting an if-else statement is shown in Figure.
The nested if-else flow-chart
Programs on nested if-else statements are as follows.
5.8 Program to print the largest of three numbers.
Explanation: Three numbers are entered. They are compared as per the theory illustrated above and the largest number is obtained and displayed