Sharp OZ-707 Operation Manual - Page 34

Storing Programs in Memory, Data Files

Page 34 highlights

Several new features are contained in this program. The WAIT command in 100 controls the 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. Notice that there are two statements in line 100 separated by a colon (:). You may put as many statements as you wish on one line (separating each by a colon) up to a maximum of 254 characters including the IENTER I key. Multiple-statement lines can make a program hard to read and modify, so it is good programming practice to use them only where the statements are very simple or there is some special reason to want the statements on one line. In this program we have used the FOR command in line 120 and the NEXT command in line 150 to create a loop. In Example 3 you created an "infinite" loop that kept repeating the statements inside the loop until 0 0 you pressed the key. With this FOR. .. NEXT loop, the computer adds 1 to N each time execution reaches the NEXT command. It then tests to see if N is larger that the limit L. If N is less than or equal to L, execution returns to the top of the loop and the statements are executed again. If N is greater than L, execution continues to line 160 and the program stops. You may use any fixed numeric variable or single-precision simple numeric variable in a FOR. ..NEXT loop, you do not have to start counting at 1 and you can increment any amount at each step. See the BASIC COMMAND DICTIONARY for details. We have labeled this program with line numbers starting with 100. Labeling programs with different line numbers allows you to have several programs in memory at one time. To RUN this program instead of the one at line 10, change to the RUN mode and enter: I CeCE I RUN100 You could also give the program a name using a label and start the program with RUN *Iabel. 56 . ------- Notes on the PRINT command: If more than eight lines must be displayed, the first lines will scroll up off the dislay, and cannot be recalled. Use the PAUSE or WAIT command in the program to display data more slowly, or use the printer. (Refer to the PAUSE, WAIT or LPRINT command.) The WAIT command applies to every PRINT command. Break long PRINT commands into a number of shorter commands if the display scrolls too quickly. Example: 100 PRINT A, B, ..., P J, 100 PRINT A, B, ..., H: PRINT I, J, ..., P Since the WAIT command is not supported by many personal computers, a wait loop such as FOR J=1 TO 500:NEXT J can also be used to extend the display time. Storing Programs in Memory You will remember that settings and functions remain in the Card even ~fter it is turned .off. Programs also remain in memory after the power 0 0 IS turned off, or It undergoes an Auto OFF. Even if you use the or I C-CE I key, the programs will remain. Programs are lost from memory only when you: • Enter NEW before beginning programming in the PRO mode. • Create a new program using the SAME LINE NUMBERS as a program already in memory. Data Files Following are some programming examples which use data file storage. Creating a Sequential File Program 1 is a short program that creates a sequential file, DATA from information you input on the keyboard. ' 57

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

Several new features are contained in this program. The
WAIT
command
in
100 controls the 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.
Notice that there are two statements in line 100 separated by a colon (:).
You may put as many statements as you wish on one line (separating
each by a colon) up to a maximum of 254 characters including the
I
ENTER
I
key. Multiple-statement lines can make a program hard to read and
modify,
so
it is good programming practice to use them only where the
statements are very simple or there is some special reason to want the
statements on one line.
In this program we have used the FOR command in line 120 and the
NEXT
command in line 150 to create a loop.
In
Example
3
you created
an "infinite" loop that kept repeating the statements inside the loop until
you pressed the
00
key. With this FOR.
..
NEXT loop, the computer
adds 1 to N each time execution reaches the NEXT command. It then
tests to see if N is larger that the limit
L.
If N
is
less than
or
equal to
L,
execution returns to the top of the loop and the statements are
executed again. If N is greater than
L,
execution continues to line 160
and the program stops.
You may use any fixed numeric variable or single-precision simple
numeric variable in a FOR.
..
NEXT loop, you
do
not have to start
counting at 1 and you can increment
any
amount at each step. See the
BASIC COMMAND DICTIONARY for details.
We
have labeled this program with line numbers starting with 100.
Labeling programs with different line numbers allows you to have
several programs in memory at one time. To RUN this program instead
of the one at line 10, change to the RUN mode and enter:
I
CeCE
I
RUN100
You could also give the program a name using a label and start the
program with RUN *Iabel.
56
.
-------
Notes on the PRINT command:
If more than eight lines must be displayed, the first lines will scroll up
off the dislay, and cannot be recalled. Use the PAUSE or WAIT
command in the program to display data more slowly, or use the
printer. (Refer to the PAUSE, WAIT or LPRINT command.)
The
WAIT
command applies to every PRINT command. Break long
PRINT commands into a number of shorter commands if the display
scrolls too quickly.
Example:
100 PRINT A,
B,
... , P
J,
100 PRINT
A,
B,
... , H: PRINT
I,
J,
...
,
P
Since the WAIT command is not supported by many personal
computers, a wait loop such as FOR
J=1
TO
500:NEXT J can also be
used to extend the display time.
Storing Programs in Memory
You will remember that settings and functions remain
in
the Card even
~fter
it is turned .off. Programs also remain in memory after the power
IS
turned off, or
It
undergoes an Auto OFF. Even if you use the
00
or
I
C-CE
I
key, the programs will remain.
Programs are lost from memory only when you:
• Enter
NEW
before beginning programming in the PRO mode.
Create a new program using the SAME LINE NUMBERS as a
program already
in
memory.
Data Files
Following are some programming examples which use data file storage.
Creating a Sequential File
Program
1
is a short program that creates a sequential file,
DATA
from information you input on the keyboard.
'
57