Commodore 2001-8 User Manual page 38

Table of Contents

Advertisement

statement to be executed before proceeding to the next line. Expressions in this form might change our
table to draw a line between the 10th and 11th value on the screen.
32 IF I = 10 THEN PRINT "
"
If we try to execute this, you will see that a line is now drawn between the tenth and eleventh value on the
screen because of the statement at line 32. It should be noted that the logical conditions of the IF and
IF-THEN are only two; either the next line is executed, or the THEN statement is executed. Take care
when placing additional programming statements on the line. For example, in:
IFX=5THEN 50:Z=A
the Z would not be executed, because the line either drops through or executes statement
50. However, in
IFX=5THEN PRINT X:Z=A
the PRINT X and Z
=
A will be executed if X
=
5.
The IF-THEN lets us make a variety of decisions at the time we are executing the program. This allows us
to Iimit the program and cause actions to happen at various points. It is the concept of the unconditional
jump plus the concept of testing values that allows the computer to be used as both control element and
legitimate computing element. The int-9lligent combination of logical decisions with repetitive operations
makes a program really work.
DATA ENTRY
Before a computer program can perform useful work, it has to be able to access a data base of some sort.
The program could require only simple data such as YES or NO responses to a game or simulation. A
more complex payroll program might need rates, hours, and tax information. In PET BASIC there are two
ways to get information into variables.
READ AND DATA STATEMENTS
Only a short time ago when there were no timeshare systems, BASIC could not accept input other than
cards included with the program. Thus, DATA statements were typed and scattered throughout the
program. The command READ was designed to pullout this DATA into variables which could be used by
the program.
When BASIC began running in an interactive environment through timeshare, verbs such as INPUT and
GET allowed direct communication with the BASIC program. READ has been relegated to inputting
parameters that change but not as often -- e.g. tables, etc.
The syntax of READ is the verb followed by a list of variables into which the DA TA is to be read.
READ
A,
B,
C,
D
READ processes DATA statements
as
they are encountered in the program. DATA statements at line 10
and 30 might be processed by
a
READ statement at line 20. DATA
is
processed sequentially and commas
and end of lines are considered terminators
10 DATA 2, -53, IE10
20 READ A,B
30 DATA 3.14, 1,06E23
Blanks and graphic characters are automatically thrown away unless they are surrounded by quotes. The
quotes are considered to be delimiters for literal characters.
String data can be typed without quotes if it does not contain literals.
50 DATA ABC, DEF
34

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents