It is also same as IF .. THEN statement, but the only difference is that, by using IF .. THEN statement we can test only one condition, and based on the condition given block of statement will be executed. But what? If we have more than one condition? At that time we have to use IF ... THEN ... ELSEIF statement. It is also called a multi-way decision statement.
Syntax:
IF [condition] THEN
[statement 1]
ELSEIF
[statement 2]
ELSEIF
[statement n]
........................
.......................
ELSE
[statement n]
END IF
Example 1
CLS
INPUT "Enter First Number "; x
INPUT "Enter Second Number "; y
INPUT "Enter Third Number "; z
IF x > y AND x > z THEN
PRINT "Greatest number is "; x
ELSEIF y > x AND y > z THEN
PRINT "Greatest number is "; y
ELSE
PRINT "Greatest number is "; z
END IF
END
Example 2
CLS
INPUT "Enter your percentage "; p
IF p >= 80 THEN
div$ = "Distinction"
ELSEIF p >= 60 THEN
div$ = "First Divistion"
ELSEIF p >= 40 THEN
div$ = "Second Division"
ELSEIF p >= 35 THEN
div$ = "Third Division"
ELSE
div$ = "Fail"
END IF
PRINT "Division ::: "; div$
END