Radio Shack TRS-80 Model 100 Basic Manual page 96

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

Advertisement

In this case, the loop of statements would be executed first with the index variable A
equal to the start value stored in the variable U. The loop would then be repeated with
the index variable A incremented by 1, i.e. A
=
U
+
1. The loop would be repeated
with increasing values for the variable A until the upper limit, determined by
computing the value of the expression Z/(Y - 2), is reached.
There would have to be a NEXT A statement located in the program after the FOR
statement to determine the end of the loop. After the last cycle through the loop with
A having the value Z/(Y - 2), execution continues with the statement immediately
after the NEXT A statement.
Lines 40 - 50 The PRINT statement prints the prompt message
SALES FOR PERIOD X
where the value of X is determined by the previous FOR statement (Line 30). The
first time through the loop, X has the value 1, so the prompt message prints as:
SALES FOR PERIOD 1
The second time through the loop, X has the value 2, so the prompt message prints as:
SALES FOR PERIOD 2
Each time through the loop, the prompt message requests the appropriate period
number because the variable X is being incremented in the FOR statement.
Note the use of semicolons in this statement. The first semicolon ensures that the
period number (X) will print immediately after the word "PERIOD." The second
semicolon tells the Computer not to move the cursor after printing the period number.
This means that the question mark
(?),
automatically printed by the following INPUT
statement, will appear immediately after the period number.
The INPUT statement waits until a number is entered from the keyboard and stores
this number in the variable Y. The variable Y acts as a temporary storage location for
the current period's sales amount.
Lines 60 • 70 These lines actually include two statements each. Line 60, for instance,
includes two assignment statements separated by a colon(:). Line 60 could have been
written in an equivalent manner with two separate line numbers as:
60 SX
=
SX
+
X
65 XX
=
XX
+
X*X
The two statements were put on the same line strictly as a matter of convenience and
to illustrate that Multiple Statements (two or more statements) can share the same line
number
if
they are separated with a colon.
The formula for a straight line requires the summation of several quantities:
• the variable SX is used to store the sum of the X values,
• the variable XX is used to store the sum of the squared X values, (Le. sum of
X*X)
• the variable SY is used to store the sum of the Y values, and
• the variable XY is used to store the sum of X times Y (i.e., the sum of X*Y.)
All variables in a program are initially set to zero by the RUN command. Each time
through the loop, the variable X is incremented to the next period number, and Y is
read in as that period's sales.
90

Advertisement

Table of Contents
loading

Table of Contents