Sharp OZ-707 Operation Manual - Page 33

Example, Complex, Programming

Page 33 highlights

Enter this program: 10: INPUT "WORD?";A$ 20: B=LEN(A$) 30: PRINT "THE WORD (";A$;") HAS" 40: PRINT B;" LETTERS" 50: END The second new element in this program is the use of the END statement to signal the completion of a program. END tells the Card that the program is completed. It is always good programming practice to use an END statement. As your programs get more complex you may wish to review them before you begin execution. To look at your program, use the LIST command. LIST, which can only be used in the PRO mode, displays programs beginning with the lowest line number. Try listing this program: LIS T IENTER I H3:I;AN$PUT "WORD?" 20:B=LEN (A$) 30:PRRDIN(T";A"T$H;E") WHO 40:PARSI"NT B;" LET TERS" Use the [K] and ~ keys to move through your program until you have reviewed the entire program. After checking your program, change to the RUN mode and run it IeeCE I RUN IENTER I HE L P ~:UN l·JORD?HELP _ RUN ~JORD?HELP THE WORD (HELP) HAS >4 LETTERS 54 This is the end of your program. Of course you may begin it again by entering RUN. However, this program would be a bit more entertaining if it presented more than one opportunity for input. We will now modify the program so it will keep running without entering RUN after each answer. Return to the PRO mode and use the CZSJ or ~ key (or LIST) to reach line 50, or enter: LIS T 5 0 IENTER I I 5e'END You may enter 50 to delete the entire line or use the [EJ key to position the cursor over the E in END. Change line 50 so that it reads: 50: GOTO 10 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 press the 00 key. When you have stopped a program using the 00 key, you can restart it using the CONT command. CONT stands for CONTinue. With the CONT command the program will restart on the line that was being executed when the 00 key was pressed. Example 4 - More Complex Programming The following program computes N factorial (NI). The program begins with 1 and computes NI up to the limit that you enter. Enter this program: 100: F = 1: WAIT 118 110: INPUT "LlMIT?";L 120: FOR N = 1 TO L 130: F = F*N 140: PRINT N,F 150: NEXT N 160: END 55

  • 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

Enter
this
program:
10:
INPUT
"WORD?";A$
20:
B=LEN(A$)
30:
PRINT
"THE
WORD
(";A$;")
HAS"
40:
PRINT
B;"
LETTERS"
50:
END
The
second
new
element
in
this
program
is
the
use
of
the
END
statement
to
signal
the
completion
of a
program.
END
tells the
Card
that
the
program
is
completed.
It
is
always
good
programming
practice
to
use
an
END
statement.
As
your
programs
get
more
complex
you
may
wish
to
review
them
before
you
begin
execution.
To
look at your
program,
use
the
LIST
command.
LIST,
which
can
only
be
used
in
the
PRO
mode,
displays
programs
beginning
with
the
lowest
line
number.
Try listing
this
program:
LIS
T
I
ENTER
I
H3:I
NPUT
"WORD?"
;A$
20:B=LEN
(A$)
30:PRINT
"THE
WO
RD
(";A$;")
H
AS"
40:PRINT B;"
LET
TERS"
Use
the
[K]
and
~
keys
to
move
through
your
program
until
you
have
reviewed
the
entire
program.
After
checking
your
program,
change
to
the
RUN
mode
and
run
it
I
eeCE
I
RUN
I
ENTER
I
HE
L P
54
~:UN
lĀ·JORD?HELP
_
RUN
~JORD?HELP
THE
WORD
(HELP)
HAS
4
LETTERS
>
This
is
the
end
of
your
program.
Of
course
you
may
begin
it
again
by
entering
RUN.
However,
this
program
would
be
a bit
more
entertaining
if
it presented
more
than
one
opportunity for input.
We
will
now
modify
the
program
so
it
will
keep
running
without
entering
RUN
after
each
answer.
Return
to
the
PRO
mode
and
use
the
CZSJ
or
~
key
(or
LIST)
to
reach
line
50,
or
enter:
LIS
T
5
0
I
ENTER
I
I
5e'END
You
may enter
50
to
delete
the
entire
line
or
use
the
[EJ
key
to
position
the
cursor
over
the
E
in
END.
Change
line
50
so
that it
reads:
50:
GOTO
10
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
press
the
00
key.
When
you
have
stopped
a
program
using
the
00
key,
you
can
restart
it
using
the
CONT
command.
CO
NT
stands
for
CONTinue.
With
the
CONT
command
the
program
will
restart
on
the
line
that
was
being
executed
when
the
00
key
was
pressed.
Example
4 -
More
Complex
Programming
The
following
program
computes N factorial
(NI).
The
program
begins
with
1
and
computes
NI
up
to
the
limit
that
you
enter.
Enter
this
program:
100:
F
=
1:
WAIT
118
110:
INPUT
"LlMIT?";L
120:
FOR
N
=
1
TO
L
130: F
=
F*N
140:
PRINT
N,F
150:
NEXT
N
160:
END
55