EasyManua.ls Logo

Radio Shack TRS-80 Model III - Page 171

Radio Shack TRS-80 Model III
274 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
BASIC
THEN statement
or line
number
Initiates the
"action clause" of an
IF-THEN type statement.
THEN is optional except
when it is required to
eliminate an ambiguity,
as in IF A
<
1 00.
THEN should
be
used
in IF-THEN-ELSE statements.
ELSE statement or line
number
Used
after IF to specify an
alternative action in case
the IF test
fails
.
(When no
ELSE
statement is used , control
falls
through
to the next
program line after
a
test fails.
)
Examples:
100 INPUT A*: IF A*
=
"YES" THEN 30© ELBE
END
In
line
100,
if
A$
equals "YES" then the
program branches
to line 300. But if
A$
does not
equal ' 'YES
'
' ,
program skips
over to the ELSE
statement which then
instructs the
Computer to end execution.
200
IF A < B THEN
PRINT "A<B" ELSE PRINT
"BOA"
If A is less than B, the
Computer prints that
fact, and then
proceeds down to the next
program line, skipping the ELSE
statement. If A
is not less than B
,
Computer jumps
directly to the ELSE statement and
prints the
specified message. Then control
passes
to
the next statement in the
program.
200 IF A>„00i
THEN B
=:
1/A-" A
=
A/5: ELSE
260
If A>.001 is True, then the
next two
statements will be executed,
assigning new
values to B and A. Then the
program will drop
down to the
next line, skipping
the
ELSE
statement.
But if A>
.001 is False, the
program jumps directly
over
to the
ELSE statement,
which then
instructs it to
branch to line 260. Note that GOTO is not
required
after ELSE.
IF-THEN-ELSE
statements
may
be nested, but
you
have
to take
care to match up the
IFsandELSEs.
810 INPUT
"ENTER
TWO
NUMBERS"?
A, B
820 IF
A
<=
B
THEN IF A <
B PRINT A;: ELSE
PRINT
"NEITHER
"
?
: ELSE
PRINT B?
830 P R I NT " I S
SMALLE
R
"
840 END
RUN the
program, inputting
various pairs of
numbers. The
program picks
out and
prints the
smaller of any
two numbers you
enter.
161

Other manuals for Radio Shack TRS-80 Model III

Related product manuals