Leave Any Decision To If - Sharp MZ-80A Owner's Manual

Hide thumbs Also See for MZ-80A:
Table of Contents

Advertisement

35
with
Leave Any
Decision
to IF
IF can
select
Even
numbers
Let's consider a program for
selecting
even numbers
only, out of many numerals, using
IF
.
.
.
GOTO
statement.
IF
has great ability to select
numbers.
10 READ X : IF X
=
-9999
THEN STOP
20 IF
X/2
< >
INT
(X/2)
GOTO
1
0
30 PRINT X
GOTO
10
40
DATA
2,
13,56,55,4,78,31
50 DATA
6,
22, 15,
19,80,
11,-9999
RUN
2 56
4
78 6
22 80
INT (X/2)
in
line number
20
is the statement
for picking
integers
alone. Therefore, if X
is
even,
X/2
< >
INT (X/2)
is
impossible, with execution advancing
to
line number 30. If
it is possible,
it's regarded as
odd, reading
the next value.
To
test
your
progress,
let's try an exercise. How can you decide the multiple of 3 or
4? You've
got it, haven't you?
The
answer
is
this.
Modification for the multiple of three
20 IF
X/3
< >
INT (X/3) GOTO 10
Modification for the multiple of four
20 IF
X/4
< >
INT (X/4) GOTO 1 0
IF can
select Maximum and
Min
10 S
=
999
: L
=
-999
20 READ X : IF X
=
-9999 THEN 80
30 IF X
>
L THEN L
=
X
40 IF X
>
S THEN S
=
X
50 GOTO
20
60 DATA 2,-5,91,256, -43
70 DATA 87,321,-76, -9999
80 PRINT "MAXIMUM VALUE
=''
;
L
90 PRINT "MIMINUM VALUE
="
,
S
100 END
RUN
MAXIMUM VALUE
=
321
MINIMUM VALUE
=
-76
Line
number
10
is very important.
Put as large
a number as possible in
variable S for substitution
of the minimum
value,
and
as small a number as
possible in variable
L
for substitution of the maximum value. What about the execution
results? Variable L and S
come
out
as
true maximum and minimum values. This is a good example of the use of
IF
...
.
THEN.
imum

Advertisement

Table of Contents
loading

Table of Contents