Sorry for the long wait, but I have been VERY busy over
the past several months. Anyway, in this lesson we will learn how to use
the If-Then Structure. This should not be a very hard concept to swallow
if you truley want to comprehend it. There are several forms of this structure,
but they are all based on the same basic one:
IF [Condition] THEN [Argument] ELSE [Alternative Argument]
Putting this in layman's terms, this means that if the condition (e.g., x
= 2) is met, the computer will carry out the argument (in other words, a
return action). If, however, the condition isn't met, then the computer
will carry out the alternative argument. If I am not mistaken, many other
computer languages have a similar structure. In BASIC, we are not limited
to one condition or one argurment. You can use the Block-IF Structure to
accomplish a more complicated conditional statement. For example:
INPUT "Enter a number: ", num
IF num > 0 and num < 10 then
PRINT "The Number is greater than 0 and Less than 10."
PRINT "The program is finished now."
ELSE
PRINT "That is not what I had hoped for."
PRINT "The program is now finished."
END IF
This example accepts human (or non human) input from the keyboard and test
the value to see if it meets the conditions of the structure. It then displays
different responses based on that input. You can choose what other conditions
would trigger responses using the "ELSE IF" command, but in the situation
where you would want to test for several different conditions with several
different outputs, you might want to use the Select-Case Structure instead
(disscussed later).
So that is just about all you'll need to know about the IF-THEN Structure.
And, I hope to see your new astounding programs in my e-mail box by seven
o'clock tonight. Just kidding, I'll give you until 8 tomorrow.