Sharp OZ-707 Operation Manual - Page 79

special, attention

Page 79 highlights

IF ...THEN ... ELSE p FORMA T: lline nUmberj l'ine numberj IF condition THEN :Klabel [ELSE :Klabel ] statement statement Abbreviation: IF T. EL. See Also: AND, OR, NOT, XOR PURPOSE: Conditionally executes a statement at the time the program is run. REMARKS: When the condition of the IF statement is true, the statement following THEN is executed; if it is false, the statement following ELSE is executed. When the ELSE statement is omitted and the condition is false, the statement following THEN is skipped. If THEN or ELSE is followed by a GOTO statement, either THEN or GOTO may be omitted (ELSE statement must be included). Example 1: IF A= x x No less than 00 < xx Less than 00 5):K(B>1) THEN .... If A is greater than 5 and B is greater than 1, the statement following THEN is executed. Logical operator "AND" may be used in place of ":K". IF (A>5)+(8>1) THEN .... If A is greater than 5 or B is greater than 1, the statement following THEN is executed. Logical operator "OR" may be used in place of "+". Using Character Strings in Relational Expressions The magnitudes of character strings can be compared when used in a relational expression of an IF...THEN ...ELSE statement. The magnitudes of character codes are compared. For example, characters A, B, and C have codes 65,66, and 67, respectively. So A is smaller than B, and B is smaller than C. EXAMPLE: 10: INPUT"CONTINUE?";A$ 20: IF A$="YES" THEN 10 30: IF A$="NO" GOTO 60 40: PRINT "YES OR NO, PLEASE" 50: GOTO 10 60: Note : Whenever a variable name is to be followed by a statement, be sure to insert a space between them, for example: 100 IF A=EL.,THEN 200 t..... A space is needed. Pay special attention to this when you use the IF, FOR, ON...GOTO, or ON...GOSUB command. 147

  • 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

IF ...THEN ... ELSE
FORMA
T:
lline nUmberj
l'ine
numberj
IF condition THEN
:Klabel
[ELSE
:Klabel
]
statement
statement
Abbreviation:
IF
T.
EL.
See
Also:
AND, OR, NOT, XOR
PURPOSE:
Conditionally executes a statement at the time the program
is
run.
REMARKS:
When the condition of the IF statement
is
true, the statement following
THEN is executed; if
it
is
false, the statement following ELSE is
executed. When the ELSE statement
is
omitted and the condition
is
false, the statement following THEN
is
skipped.
If THEN or ELSE
is
followed by a GOTO statement, either THEN or
GOTO may be omitted (ELSE statement must be included).
Example 1:
IF A<5 THEN
C=A:KB
:GOTO 50
If A is smaller than
5,
then assign the product,
A:KB,
to
C and go to
line 50.
Example 2:
IF B=C+1 GOTO 60 ELSE 100
or
IF B=C+ 1 THEN
60
ELSE 100
If B equals C+
1,
then go to line 60; otherwise go to line 100.
146
p
The condition (e.g. A<5) of the IF statement can be any relational
expression as listed below:
Relational expression
Description
00
=
xx
Equal to
00
>
xx
Greater than
00
>= x x
No
less than
00
<
xx
Less than
00
<=
xx
No
greater than
OO<>
xx
Not equal to
Note: 0 0 and x x represent expressions (5*4,
A,
8,
etc.).
More than one relational expression can
be
linked with the logical
operators
'':+:''
or "
+".
For example:
IF
(A>5):K(B>1) THEN
....
If A
is
greater than 5
and
B is greater than
1,
the statement followi
ng
THEN is executed. Logical operator "AND" may be used in place of
":K"
.
IF (A>5)+(8>
1)
THEN
....
If A
is
greater than 5 or B
is
greater than
1,
the statement following
THEN is executed. Logical operator "OR" may be used
in
place of "+".
Using Character Strings in Relational Expressions
The magnitudes of character strings can be compared when used
in
a
relational expression of
an
IF
...THEN .
..
ELSE statement. The
magnitudes of character codes are compared. For example, characters
A,
B,
and C have codes
65,66
, and 67, respectively.
So
A
is
smaller
than
B,
and B is smaller than C.
EXAMPLE:
10: INPUT"CONTINUE?";A$
20:
IF
A$="YES" THEN 1
0
30:
IF
A$="NO" GOTO
60
40: PRINT "YES
OR
NO,
PLEASE"
50: GOTO 10
60:
Note:
Whenever a variable name is to be followed by a statement,
be
sure to
insert a space between them, for example:
100 IF A=EL.,THEN 200
t
.....
A space
is
needed.
Pay
special
attention
to
this
when
you
use
the
IF,
FOR,
ON
.
..
GOTO,
or
ON ... GOSUB command.
147