When an if statement is present inside another if statement, called nested if statement.
Now the message for an even value is displayed only if the value of number is also less than 40. There are three possible outcomes from this code fragment. If number is even and less than 40, you will see the message to that effect,
if number is even and is not less than 40, there will be no output, and finally if number is odd, a message will be displayed.
If-else-if Ladder: It is based upon a sequence of nested ifs. The general form of the if-else-if ladder is :
The if statements are executed from the top down. Once one of the condition is true, the statement associated with that if is executed, and rest of the ladder is neglected. If none of the conditions is true, then the final else statement will be executed.
If there is no final else and all other conditions are false, then no action will take place.
Let's see a program to demonstrate if-else-if ladder:
enter the marks