� � � � A% = 5
� � � � IF A% > 0 THEN PRINT "A% = "; A% ELSE PRINT "A% is 0"
A% = 5
� � � � INPUT "What is Your Name"; name$
� � � � IF name$ = "Nable" THEN PRINT "Your Name is Nable."
� � � � IF name$ = "Bill" THEN PRINT "Your Name is Bill."
What is your Name? Nable
Your Name is Nable.
Okay, now that you've got the general Idea of how an IF-THEN statement works, we can do something
a little more complicated; AND and OR statements.
AND and OR are examples of 'logical operators' which, in this case, just allow you to test for more than one condition in a
given statement. There are 6 logical operators in QBasic, however their use is more complicated than this tutorial will cover, so
they will be ommited, if you are that interested in what they are and do you can find them in the help file. So for now we'll stick to
our discussion of AND and OR, here is an example:
� � � � A% = 10
� � � � IF A% <= 5 OR A% >= 10 THEN PRINT "The value of A% is: "; A%
� � � � IF A% >= 5 AND A% <= 50 THEN PRINT "The value of A% is still: "; A%
� � � � The Value of A% is: 10
� � � � The Value of A% is still: 10
� � � � There are some times when you will find it necessary to execute more than one line of code as a result of some condition. There
are, generally, two ways to do this, the first is inline, where you just place a colon after each operation you perform.
Example:
� � � � A% = 1
� � � � IF A% > 0 THEN PRINT "A% is greater than 0": END
� � � � A% is greater than 0
� IF condition THEN
� � 'Some code goes here
� END IF
This is just like a normal IF statement, except that if you put anything on the same line as, and after, the THEN, you will
get an error, you also have to remember to place the END IF at the end of the code that you wish to execute.
Example:
� � � � A% = 5
� � � � IF A% = 5 THEN
� � � � � PRINT "A% is 5"
� � � � � END
� � � � END IF
� � � � A% is 5
Here is an example:
� � � � A% = 10
� � � � IF A% = 5 THEN
� � � � � PRINT "A% is 5"
� � � � � END
� � � � ELSEIF A% = 10 THEN
� � � � � PRINT "A% is 10"
� � � � � END
� � � � END IF
� � � � A% is 10
� � Back � � | � � Tutorial Part 1 � � | � � Next � � |