Sunday, June 30

READ and DATA statement

The READ statement is used to read value from a DATA statement and assign them to variables.
The DATA statement is used to store the numeric, integer or string constants that are accessed by the READ statement.
Syntax
LN READ  list of variable
LN DATA constants
Where,
LN  :  Line Number
list of variables : numeric or string variables
Constants  : numeric or string data

  • A READ statement must always be used with a DATA statement.
  • READ statements assign variables to DATA statement values on a one- to - one basis.
  • READ statement variables may be numeric or string and DATA statement values {constants} must agree READ statement variables.
  • A single READ statement can access one or more DATA statement.
  • Several READ statements can access the same DATA statement.
  • String constant in DATA statements should be enclosed within double quotation marks.
  • DATA statements are not executable and may be placed any where in the program.
  • The variables in the READ statement are separated by a comma [,] similarly the constant in DATA statements are also separated by commas.
    Examples

1. 10  READ A, B
    50  DATA 10,20
The values assigned to the variables A and B of READ statement from the constants of DATA statements are as follows
A = 10
B = 20

2.  10 READ A, B, A1, A2, C% ,D%, A$, B$, X$
      80 DATA 1.7, -4.986, 2E-7, -1.2 E 6, 12,70 ,"BEAUTIFUL", "CITY" "POKHARA"
It assigns the following values to the variables :
A = 1.7
B = -4.986
A1 = 2E - 7
A2 = -1.2E6
C% = 12
D% = 70
A$ = "BEAUTIFUL"
B$ = "CITY"
X$ = "POKHARA"

       

       

             

No comments:

Post a Comment