Radio Shack TRS-80 Model 100 Basic Manual page 53

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

To accomplish this, the program must be able to test whether or not sales (ST) is
greater than $2000, and branch accordingly. This can be done with the use of the
IFITHEN statement.
The
inequ~lity
ST> 2000·
appearing in line 30 (between IF and THEN) is called a "condition." If this condition
is false, then the next statement to be executed is in line 40. On the other hand, if the
condition is true, then the statement following THEN:
CM
=
CM
+
.20
*
(ST - 2000)
will be executed before control passes on to line 40. In other words, if total sales are
not greater than 2000, no additional calculations are performed in line 30. But, if total
sales are greater than 2000, the additional commission is calculated and added to the
original flat rate commission.
The general format of the IF/THEN statement is
IF
"condition"
THEN
"statement"
where
"statement"
is executed only when
"condition"
is true. In either case, the
next line executed is the one following the IFITHEN statement.
The condition is usually the comparison of two numeric or string expressions. Two
numeric expressions are compared with the use of a relational operator. In this case,
..>"
in line 30 is the relational operator.
Here is a table of numeric relational operators:
numeric operator
meaning
>
greater than
<
less than
< >
or
> <
not equal to
>
=
or
=
>
greater than or equal to
< =
or
= <
less than or equal to
Assuming the variable A has the value
2,
the logical values of some conditions
are
given below.
condition
A>l
A
< -
1
A
< >
1
A
>=
2
A
<=
0
logical value
true
false
true
true
false
Here are some more examples of valid IF/THEN statements
55 IF A
*
B - C
<
D THEN A
=
B
65 IF 5.6
< >
AB - 4.6 THEN STOP
75 IF CD/AC
< >
1 THEN CD
=
AC
47

Advertisement

Table of Contents
loading

Table of Contents