Casio CFX-9800G-w Owners Manual - Page 171

Casio CFX-9800G-w - Color Graphing Calculator Manual

Page 171 highlights

'About Conditional Jumps With a conditional jump you set up certain criteria and control whether or not the jump is actually performed. Look at the following format. a. If true Left side Relational operator Right s' ide Statemt ent : Statement If not true As shown above, if the condition defined by the relational operator is true, the statement following " " is executed, and then the next statement is executed. If the condition is false, the statement following is skipped, - The following are the conditions that you can define using the relational operators. L = True when L and R are equal; false when L and R are not equal L R True when L and R are not equal; false when L and R are equal L> R True when L is greater than R; false when L is less than or equal to R L,-A, A, =, 0, Goto, 2, : , A, +, B B, Goto, 1, :, Lbl, 2, :, B 31 bytes With this program, 0 is assigned to value memory B to clear it. The next statement prompts for input of a value to value memory A. The next statement is a conditional jump that says: "if the value input for A equals 0, then go to label 2". The statement following label 2 (Lbl 2) ends program execution with a display of the value memory B contents. For other values, the next statement adds value memories A and B, and then stores the result in value memory B again. After this, program execution returns to the statement following label 1 (Lbl 1), where the next input for A is prompted. -306- •About Count Jumps There are two count jumps: one that increments a value memory (Isz) and one that decrements a value memory (Dsz). Look at the following formal Memory contents %0 Cil Isz Memory name : Statement Statement Memory contents = 0 Memory contents 40 I Dsz Memory name : Statement a . Statement Memory contents = 0 As shown above, if the increment or decrement operation. does 'not cause the content of the value memory to become 0, the statement following the value memory name is executed. If the content of the value memory becomes 0, the next statement is skipped. • To use a count jump Example 1 To write a program that accepts input of 10 values, and then calculates the average of the values. Program 1, 0, A, :,0, C, : , Dsz, A; :, Goto, 1, :, C, + , 1, 0 32 bytes This program starts out by assigning a value of 10 to A. This is because value memory A will be used as a control variable. The next statement clears C to zero. After defining the location of label 1 (Lbl 1), the program then prompts for input of a value for B. The next statement adds the value of B to value memory C, and then stores the result in C. The next three statements say: "decrement the value in A, and if it is still greater than 0, jump back to label 1; otherwise divide the contents of C by 10". Example 2 To write a program that calculates at 1-second intervals the altitude of a ball thrown into the air atan initial velocity of Vm/sec and an angle of, S°. The formula is expressed as: h=lbsinSt --;igt2, with g =9.8. The effects of air resistance should be disregarded. Program Deg, :, 0, T, : ,?, V, :, ?, -',S, Lbl, 1, :, Isz, T, :, V, x, sin, S, x, T, -, 9, •, 8, x , T, x2, , 2, 4, Coto, 1 38 bytes -307- A340087-13

  • 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
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206

'About
Conditional
Jumps
With
a
conditional
jump
you
set
up
certain
criteria
and
control
whether
or
not
the
jump
is
actually
performed.
Look
at
the
following
format.
a.
If
true
Relational
'
t
Left
side
Right
side
Statement
:
Statement
operator
If
not
true
As
shown
above,
if
the
condition
defined
by
the
relational
operator
is
true,
the
statement
following
"
"
is
executed,
and
then
the
next
statement
is
executed.
If
the
condition
is
false,
the
statement
following
is
skipped,
-
The
following
are
the
conditions
that
you
can
define
using
the
relational
operators.
L
=
True
when
L
and
R
are
equal;
false
when
L
and
R
are
not
equal
L
R
True
when
L
and
R
are
not
equal;
false
when
L
and
R
are
equal
L>
R
True
when
L
is
greater
than
R;
false
when
L
is
less
than
or
equal
to
R
L<R
True
when
L
is
less
than
R;
false
when
L
is
greater
than
or
equal
to
R
L≥
R
True
when
L
is
greater
than
or
equal
to
R;
false
when
L
is
less
than
R
L≤
R
True
when
L
is
less
than
or
equal
to
R;
false
when
L
is
greater
than
R
To
use
a
conditional
jump
To
write
a
program
that
calculates
the
square
root
of
any
input
value
that
is
greater
than
or
equal
to
zero.
If
a
value
that
is,less
than
zero
is
input,
the
program
ignores
it
and
prompts
further
input.
Lbl,
1,
?,
A,
:,
A,
≥,
0,
C,
A,
A
,
Goto,
1
16
bytes
Example
1
This
program
starts
out
by
prompting
input
for
A.
The
next
statement
tests
the
input
by
saying:
"if
the
value
of
A
is
greater
than
or
equal
to
0,
then
calculate
the
square
root
of
A".
This
is
followed
by
a
display
result
command:
After
the
result
is
displayed,Rressing
E
continues
with
the
Goto
-1
unconditional
jump
to
label
1
(Lbl
1)
at
-the
beginning
of
the
program.
For
values
that
are
less
than
0,
the
square
root
calculation
statement
is
skipped
and
execution
jumps
directly
to
the
Goto
1 statement.
Example
2
To
write
a
program
that
accumulates
inputvalues,
but
displays
the
total
of
the
values
any
time
zero
is
entered.
Program
0
,
B,
Lbl,
1,
?,
->,-A,
A,
=,
0,
Goto,
2,
:
,
A,
+,
B
B,
Goto,
1,
:,
Lbl,
2,
:,
B
31
bytes
With
this
program,
0
is
assigned
to
value
memory
B
to
clear
it.
The
next
statement
prompts
for
input
of
a
value
to
value
memory
A.
The
next
statement
is
a
conditional
jump
that
says:
"if
the
value
input
for
A
equals
0,
then
go
to
label
2".
The
statement
following
label
2
(Lbl
2)
ends
program
execution
with
a
display
of
the
value
memory
B
contents.
For
other
values,
the
next
statement
adds
value
memories
A
and
B,
and
then
stores
the
result
in
value
memory
B
again.
After
this,
program
execution
returns
to
the
statement
following
label
1
(Lbl
1),
where
the
next
input
for
A
is
prompted.
—306—
•About
Count
Jumps
There
are
two
count
jumps:
one
that
increments
a
value
memory
(Isz)
and
one
that
decre-
ments
a
value
memory
(Dsz).
Look
at
the
following
formal
Memory
contents
%0
Cil
Isz
Memory
name
:
Statement
Statement
Memory
contents
=
0
Memory
contents
40
I
a
Dsz
Memory
name
:
Statement
.
Statement
Memory
contents
=
0
As
shown
above,
if
the
increment
or
decrement
operation
.
does
'not
cause
the
content
of
the
value
memory
to
become
0,
the
statement
following
the
value
memory
name
is
executed.
If
the
content
of
the
value
memory
becomes
0,
the
next
statement
is
skipped.
To
use
a
count
jump
To
write
a
program
that
accepts
input
of
10
values,
and
then
calcu-
lates
the
average
of
the
values.
Example
1
Program
1,
0,
A,
:,0,
C,
:
,
Dsz,
A;
:,
Goto,
1,
:,
C,
+
,
1,
0
32
bytes
This
program
starts
out
by
assigning
a
value
of
10
to
A.
This
is
because
value
memory
A
will
be
used
as
a
control
variable.
The
next
statement
clears
C
to
zero.
After
defining
the
location
of
label
1
(Lbl
1),
the
program
then
prompts
for
input
of
a
value
for
B.
The
next
statement
adds
the
value
of
B
to
value
memory
C,
and
then
stores
the
result
in
C.
The
next
three
statements
say:
"decrement
the
value
in
A,
and
if
it
is
still
greater
than
0,
jump
back
to
label
1;
otherwise
divide
the
contents
of
C
by
10".
Example
2
To
write
a
program
that
calculates
at
1
-second
intervals
the
altitude
of
a
ball
thrown
into
the
air
at
an
initial
velocity
of
Vm/sec
and
an
angle
of,
S°.
The
formula
is
expressed
as:
h=lbsinSt
--;igt
2
,
with
g
=9.8.
The
effects
of
air
resistance
should
be
disregarded.
Program
Deg,
:,
0,
T,
:
,?,
V,
:,
?,
-'
,S,
Lbl,
1,
:,
Isz,
T,
:,
V,
x,
sin,
S,
x,
T,
—,
9,
•,
8,
x
,
T,
x
2
,
,
2,
4,
Coto,
1
-307-
38
bytes
A340087-13