BASIC8.WPS

BASIC LANGUAGE PROGRAMMING

USING READ/DATA STATEMENTS

Data can be read into a program by using a "READ" statement

combined with a "DATA" statement.

EXAMPLE : READ A,B

CLS

C = A + B

PRINT C

DATA 2,4

END

The program above will read the number 2 in as a value for the variable A and the number 4 in as a value for the variable B. The line of the program which reads C= A + B will add 2 + 4 and make C equal to 6. The PRINT C line will then print

the 6.

EXAMPLE #2 :

CLS

READ NAME$, CITY$

PRINT NAME$, CITY$

DATA CHARLIE, LINDSAY

END

NOTE: When values are assigned to string variables using READ/DATA statements you need NOT put text information in "".

The program above will read the name Charlie into the NAME$ variable and the word Lindsay into the CITY$ variable and then print them out.

 

EXAMPLE #3 :

CLS

FOR X = 1 TO 3

READ NAME$, ADDRESS$, CITY$

PRINT NAME$, ADDRESS$,CITY$

NEXT X

DATA TOM, 19 CHURCH ST.,LINDSAY

DATA JIM, 23 POOL ST., LITTLE BRITAIN

DATA BILL, 67 KENT ST., LINDSAY

END

The program above will run around the loop 3 times and

read address information into the read statement variables

and then print them out each time through.

 

 

Assignment:

Make a BASIC program to read the names, addresses and postal codes of 10 friends and then print them out in a format which would appear normal on a letter.

Copyright - Barry Boyle (bboyle@kawartha.net)