Beginner's Programming Tutorial in QBasic

(Kiana) #1
TIP: after There is a way to have IF...THEN without using multiple END IF commands. To do
so, place a colon between each command.
IF (x = 5) THEN INPUT a$: PRINT a$

ELSEIF


The ELSEIF command allows you to perform a secondary action if the first expression was false.
Unlike ELSE, this task is only performed if a specified statement is true.
x = 6
IF (x = 5) THENPRINT "Statement 1 is true"
ELSEIF (x = 6) THENPRINT "Statement 2 is true"
END IF
Output:
Statement 2 is true


You can have multiple ELSEIF commands, along with ELSE.
x = 8
IF (x = 5) THENPRINT "Statement 1 is true"
ELSEIF (x = 6) THENPRINT "Statement 2 is true"
ELSEIF (x = 7) THEN
PRINT "Statement 3 is true"
ELSEPRINT "No above statements are true"
END IF
Output:
No above statements are true

Free download pdf