Sharp MZ-700 Series Owner's Manual page 45

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

Advertisement

Try running the program shown above. Inclusion of character strings in the PRINT
and INPUT statements provides a clear indication of the program's operation.
Practical computer programs consist of combinations of sequences similar to the
one shown here. By combining commands, statements, and sequences in different
manners, you will soon find that there are many different methods of achieving
a desired result.
2. 3. 5. 4 GET
Format
Function
GET v
v
Numeric variable or array element, or string variable or array element.
When this statement is encountered during program execution, the BASIC inter-
preter checks whether any key on the keyboard is being pressed and, if so, assigns
the corresponding value to the variable specified in v. Whereas the INPUT statement
prompts for entry of data and waits until that data has been entered before resuming
execution, the GET statement continues execution regardless of whether any key
is being pressed.
Although data is substituted into variable v by the GET statement if any keys are
pressed when the statement is executed, the variable will be left empty (0 for a
numeric variable or null for a string variable) if no keys are pressed.
With numeric variables, this statement allows a single digit (from 0 to 9) to be
entered; with string variables, it allows a single character to be entered.
This statement can be extremely useful when you want to enter data without
pressing the [CR| key, as is often the case with game programs.
(Example:)
1 0
20
3 0
4 0
5 0
6 0
P R I N T
" N E X T
G E T
A S
I F
A $ = " Y "
T H E N
G O ? CY O R
N )
5 0 -
In
the
example
above,
execution
jumps from line 30 to line 50 if the
value of variable A$ is "Y".
G O T O
2 0
Line 40 unconditionally transfers exe-
P R I N T
" P R O G R A M
E N D " cution to line 20.
E N D
This program displays the prompt " NEXT GO? (Y OR N)" and waits for input.
When the Y key is pressed, execution moves to line 50 and the program ends.
Until that time, however, execution loops repeatedly between lines 20 and 40.
Now delete lines 30 and 40 and try executing the program again. As you can see,
execution is completed immediately regardless of whether any keys have been
pressed.
Note: When GET statements are executed in succession, a routine should be includ-
ed between them to ensure that each is completed before going on to the
next. The reason for this is that key chatter (vibration of the contacts of
the key switches) may result in two GET statements being executed simul-
taneously.
43

Advertisement

Table of Contents
loading

Table of Contents