Example4-More Complex Programming - Sharp PC-1403 Operation Manual

Hide thumbs Also See for PC-1403:
Table of Contents

Advertisement

98
In
addition
to executing different programs by
giving
their
starting
l
i
ne
number,
you
can
give programs an
alphabetical
name and
start them
with
the ~
key (see Chapter
6).
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
I
ENTER
I
.
Also
in
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
SO-character
maximum including
I
ENTER
I
.
Multiple
statement lines can make a
program
hard to
read and
modify,
however,
so it is a 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.
Also
in this
program,
we have used the
FOR
verb in line 120 and the
NEXT
verb
in line
150 to
create a loop.
In
Example
3,
you created an
"infinite"
loop which kept
repeating the
statements
inside the loop
until
you pressed the
~
key.
With
the FOR/
NEXT
loop,
the
computer
adds
1
to
N
each time
execution
reaches the NEXT
verb.
It
then
tests to see if N is larger than
the
limit
L.
If N
is less than or
equal
to
L,
execution
returns
to
the
top
of the
l
o op and the statements are executed
again.
If
N
is
greater than
L,
execution
continues
with
line 160 and
the
program
stops.
You may use any
numeric
variable
in
a FOR/NEXT
loop.
You also
do
not have to start
counting at 1 and
you
can add
any amount
at
each
step.
See
Chapter
8 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
enter:
RUN
100
Although the computer has a
factorial
function,
we will use an example of the
factorial
computation in this section
to
explain
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 this
program.
100
F
=
1:
WAIT 118
110
INPUT
"LIMIT?";
L
120
FOR N
=
1
TO L
130F=F*N
140
PRINT
N,
F
150 NEXT N
160
END
Example 4- More Complex Programming
Programming the
Computer

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents