Sharp MZ-700 Series Owner's Manual page 55

Personal computer
Hide thumbs Also See for MZ-700 Series:
Table of Contents

Advertisement

Format
Function
Example
2. 3. 6. 5 IF ~ GOTO
(abbreviated format: IF ~ G.)
IF e GOTO Lr
e:
Relational expression or logical expression
Lr: Destination line number
This statement sequence evaluates the condition defined by relational or logical
expression e, then branches to the line number specified in Lr if the condition is
satisfied. As with the IF . . . THEN sequence, IF ~ GOTO is used for conditional
branching; when the specified condition is satisfied, program execution jumps to
the line number specified in Lr. If the condition is not satisfied, execution continues
with the next line of the program. (Any statements following IF ~ GOTO on the
same program line will be ignored.)
1 0
G=0:N=0
2 0
I N P U T
" G R A D E = "
; X
I F
X = 9 9 9
G O T O
1 0 0
T = T + X : N = N + 1
G O T O
2 0
P R I N T
"
"
T O T A L : " ; T
N O .
P E O P L E : " ; N
A V E R A G E : " ; T / N
3 0
4 0
5 0
1 00
1 1 0
1 2 0
1 3 0
1 4 0
P R I N T
P R I N T
P R I N T
E N D
Format
Function
Example
2. 3. 6. 6 IF ~ GOSUB
(abbreviated format: IF ~ GOS.)
IF e GOSUB Lr
e:
Relational expression or logical expression
Lr: Destination line number
This statement evaluates the condition defined by relational or logical expression e,
then, if the condition is satisfied, branches to the subroutine beginning on the
line number specified in Lr. Upon completion of the subroutine, execution returns
to the first executable statement following the calling IF ~ GOSUB statement;
therefore, if multiple statements are included on the line with the IF ~ GOSUB
statement, execution returns to the first statement following IF ~ GOSUB.
1 0
I N P U T
2 0
I F
X < 0
3 0
I F
X = 0
4 0
I F
X > 0
5 0
P R I N T
"
6 0
G O T O
1 0
1 0 0
P R I N T
2 0 0
P R I N T
3 0 0
P R I N T
X =
" ; X
G O S U B
1 0 0
G O S U B
2 0 0
G O S U B
3 0 0
P R I N T " X < 0
P R I N T "
X = 0
P R I N T " X > 0
X
P R O G R A M
L I N E
1 0 0
X
P R O G R A M
L I N E
2 0 0
X
P R O G R A M
L I N E
3 0 0
R E T U R N
R E T U R N
R E T U R N
53

Advertisement

Table of Contents
loading

Table of Contents