Else if

Updated: 04/26/2017 by Computer Hope

Alternatively referred to as elsif, else if is a conditional statement performed after an if statement that if true performs a function. Below is an example of an if, elsif, and else conditional statement in Perl.

print "Enter number: ";
my $number = <STDIN>;
if ($number <= 10) {
print "Your number is less than or equal to 10";
elsif ($number <= 50) {
print "Your number is more than 10, but less than 50";
else {
print "Your number is greater than 50";

The above example shows how elsif could be used to create an additional conditional statement and not just a simple if or else statement. The above example could also be extended by adding as many elsif or else if statements as the program needed.

Not all programming languages are the same, although this above example used elsif, in a different language such as ANSI C you would use else if, or elif may be used with Python.

Conditional statement, Else, If statement, Programming terms