Beginner's Programming Tutorial in QBasic

(Kiana) #1

Output:
x is greater than or equal to 5x is less than or equal to 5


ELSE


Using the is false. ELSE command, you can have the program perform a different action if the statement


x = 3
IF x = 5 THEN PRINT "Yes" ELSE PRINT "No"
Since X doesn't equal 5, the output is:
No


END IF


END IF allows you to have multiple commands after the IF...THEN statement, but they must
start on the line after the IF statement. END IF should appear right after the list of commands.
x = 5
IF (x = 5) THEN
INPUT a$
PRINT a$
END IF


The following program uses ELSE with the END IF command:
x = 16
IF (x = 5) THEN
INPUT a$PRINT a$
ELSE
PRINT x * 2
END IF
Output:
32

Free download pdf