Beginner's Programming Tutorial in QBasic

(Kiana) #1

Multiple expressions


You can have more than one expression in IF...THEN by using either the OR operator or the
AND operator.
The OR operator only requires one expression to be true in order to print "Yes" in the following
program:
x = 20
IF (x = 5 OR x = 20) THEN PRINT "Yes"
Output:
Yes


The AND operator requires both expressions to be true.
x = 7
IF (x > 5 AND x < 10) THEN PRINT "True"
Output:
True


This is a slightly more complex example:
x = 16y = 3
IF ((x > 5 AND x < 10) OR y = 3) THEN PRINT "Correct"
Output (since Y is 3):
Correct


Strings in IF...THEN


So far in this chapter, we've only been dealing with numbers, but you can also use strings with
the IF...THEN command.
x$ = "Hello"
IF (x$ = "Hello" OR x$ = "World") THEN PRINT x$
Output:
Hello

Free download pdf