Example 4 - More Complex Programming - Radio Shack TRS-80 PC-3 Owner's Manual

Table of Contents

Advertisement

Now RUN the modified program.
The GOTO statement causes the program to loop (keep repeating the same operation). Since you put no limit on the loop it will
keep going forever (an "infinite" loop). To stop this program hit the BREAK (
~
) key.
When you have stopped a program using the
~
key, you can restart it using the CONT command. CONT stands for CONTinue.
With the CONT command, the program will restart on the line which was being executed when the
~
key was pressed.
Example 4 - More Complex Programming
The following program computes N Factorial (N!). The program begins with 1 and computes N! up to the limit which you enter.
Enter th is program.
100 F
=
1: WAIT 128
110 INPUT "LIMIT? "; L
120 FOR N
=
1 TO L
130 F
=
F
*
N
140 PRINT N, F
150 NEXT N
160 END
Several new features are contained in this program. The WAIT verb in line 100 controls the length of time that displays are held
before the program continues. The numbers and their factorials are displayed as they are computed. The time they appear on the
display is set by the WAIT statement to approximately 2 seconds, instead of waiting for you to press
(ENTER)
.
Also on line 100, notice that there are two statements on the same line separated by a colon ( :). You may put as many statements
as you wish on one line, separating each by a colon, up to the 80-character maximum including
(ENTER)
.
Multiple statement
69

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents