else if statement is used along with the
else statements. It is used to execute blocks of code conditionally when there are more than two conditions.
In the example give below,
the value of the
number variable is
ifstatement checks if the number is greater than 0.
else ifstatement checks if the number is equal to 0.
elsecondition executes when none of the previous conditions is met.
Since the value of
number is 0, the code in the
else if block executes.
We can change the value of
number to -1 and see that the code inside the
else statement executes.
Depending upon the number of conditions, we can add as many
else if statements as needed. They must be added between the