else - to execute code block if condition is not met.
else if - to check alternative condition if the main one is false.
else
else if
Let's look at a program that checks whether speed is above or below the speed limit for cities (50 km/h).
Output:
Since the condition at line 3
is false, the code
inside else block executes.
Let's have a program that categorizes a person depending on his/her height.
Rules are the following:
Output:
Since the condition at line 3
is false and the
condition at line 6
is true, the code inside else if block executes.