READ and DATA Statements - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

READ and DATA Statements

Description:

READ statements find DATA statements and match variables and values in the order listed. ... READ Car$, Miles, Gallons. DATA 'Buick', 290, 14. READ Score1, ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 17
Provided by: reneec4
Category:
Tags: data | read | statements

less

Transcript and Presenter's Notes

Title: READ and DATA Statements


1
READ and DATA Statements
  • Computer Programming 1-2
  • 2000-2001

2
READ and DATA Statements
  • Use when there is a large volume (a lot) of
    input.
  • READ actually performs the input.
  • DATA lists values to be entered by READ.
  • READ Name, Age
  • DATA Nancy, 15

Instead of LET NameNancy LET Age15
3
Data is entered into main memory (RAM) with a
variable assigned to represent it later in the
program.
4
READ and DATA Statements
  • READ statements go in the main programwherever
    the input step is to occur.
  • READ statements find DATA statements and match
    variables and values in the order listed.

5
READ and DATA examples
  • READ Car, Miles, Gallons
  • DATA Buick, 290, 14
  • READ Score1, Score2, Score3
  • DATA 100, 200, 300

6
Rules for READ and DATA
  • Variables in _____ statements are matched to
    constants in _____ statements.
  • _____ statements contain one or more variables,
    separated by _____.
  • _____ statements contain one or more constants,
    separated by _____.

7
Rules for READ and DATA
  • DATA statements are placed after the END
    statement.
  • The number of variables in READ should match the
    number of constants in DATA.
  • The data type of the variables in READ must match
    the data type of the constants in DATA,
  • AND THEY MUST BE IN THE SAME ORDER!

8
Errors with READ and DATA
  • READ Song, Sales
  • DATA Hey, Jude, 1000000
  • DATA Hey, Jude, 1000000
  • DATA 1000000, Hey, Jude
  • DATA Hey, Jude
  • DATA 1000000

9
Errors with READ and DATA
  • Items listed in READ and DATA statements must
    match in number and by data type or you will get
    a syntax error.
  • There must be enough DATA items to match with the
    READ variables or you will get an out of data
    error.

10
Show the output
  • READ A1, A2, A3
  • Sum A1 A2 A3
  • PRINT Sum Sum
  • END
  • DATA 15, 8, 2

11
Show the output
  • READ P, Moon
  • READ Num
  • PRINT P has at least
  • PRINT Num Moon
  • END
  • DATA Jupiter, moons, 16

12
Show the output
  • READ A, B
  • PRINT A is a B
  • READ C
  • PRINT A is a C
  • END
  • DATA Pluto, dog, planet

13
Debug
  • READ Name, Age
  • PRINT Name isAgeyears old.
  • END
  • DATA Jody, 5

14
Debug
  • READ Lngth, Wdth
  • LET Area Lngth Wdth
  • PRINT Area Area
  • END
  • DATA 120, 86

15
Debug
  • READ Year, Car
  • PRINT I have a Year Car
  • END
  • DATA Toyota, 1998

16
You try it!
  • Change your grade program to use READ and DATA
    instead of LET for input. Save with the same
    name.
  • Change two other LET or INPUT programs. Resave.
  • MYINFO.BAS

17
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com