Sunday, July 7

SWAP Statement

The SWAP statement is used to exchange the values of two variables.
Syntax
LN SWAP variable1, varaible2
Where,
LN      :  Line Number 
variable1  :  the first variable
variable2  :  the second variable

  • Any type of variable may be swapped (numeric or string).
  • To use SWAP, the two variables must be of the same type.
Use of SWAP statement in the program.

  CS 5.12 Display on the screen for SWAP statement

Ok
 LIST 
5      REM Learning the use of SWAP statement
10    A$ = "STUDENTS"  :  B$ = "TEACHERS"  :   C$ = "HELP"
20    PRINT A$, C$, B$
30   SWAP A$, B$
40  PRINT A$, C$, B$
50  END
Ok
RUN
STUDENTS     HELP  TEACHERS
TEACHERS     HELP  STUDENTS                     
Ok

Saturday, July 6

RESTORE Statement

The restore statement allows DATA statements to be reread from a specified line.
Syntax
LN RESTORE [Line Number]
Where,
LN      :           Line Number
Line number    :       The particular line number from which data are to be read again.
  • if line number is specified the next READ statement reads the first data in the specifed DATA statement.
  • if line number is omitted, the next READ statement reads the first data in the first DATA Statement.
Example

10  RESTORE
Use the RESTORE Statement in program

CS 5.11 Display on the screen for RESTORE statement

2  REM  Learning use of RESTORE statement
5  READ A, B, C
10  RESTORE
15  READ D, E, F
20 DATA 1.8, 5.02, 8, 20, -47, 0.003
40 PRINT A, B, C, D, E, F
50 END

Explanation of the program
This program will assign the following values to the variables
A = 1.8
B = 5.02
C = 8
D = 1.8
E = 5.02
F = 8
The RESTORE statement results the pointer to the beginning of the line 20. 
In the absence of the RESTORE statement (i.e. line 10) , the following values would be assigned to the variables.
A = 1.8
B = 5.02
C = 8
D = 20
E = -47
F = 0.003      

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"

       

       

             

Wednesday, June 19

INPUT Statement

The INPUT Statement is used to prepare the program for input from the keyboard during program execution.
Syntax
LN INPUT [Prompt string ;] List of Variables
Where,
LN      :       Line Number
Prompt String  :    Message displayed for data to be supplied during program execution.
List of Variable  : Contains the variable {s} that store data

  • The prompt string must be surrounded by double question marks, followed by a semicolon or comma and name of variables to which it will be assigned.
  •  If more than one variable is used, they must be separated by commas. Similarly, values entered for different variables should be separated by commas. 
  • The data entered is assigned to variable list. The number of data items supplied must be the same as the number of variables in the list.
  • The variable names in the list may be numeric, integer, string or sub scripted variable.
  • If it is necessary that the data supplied must be of the same type as the variable in the input statement.
  • Comma may be used , instead of semicolon, after prompt string to suppress the question mark.
  • When INPUT statement is encountered during program execution, the program halts (stops) and prints a question mark{?} {or the prompt string is displayed }, then you can enter data and if you press Enter, program execution continues.
  • Quotation marks are optioned in string type of data.
Examples 
The following are some of valid INPUT statements
1. 10  INPUT A
2. 20  INPUT A,B,C
3. 30 INPUT A$, A2$, B1, B2, C1%, C2%
4. 40 INPUT A, B$, D(5)

CS 5.7 Display on the screen for INPUT statement

Ok
LIST 
10    REM Learning the use of INPUT statement
20    REM Value of two numbers X and Y
30    INPUT X
40    INPUT Y
50    REM Addition of two numbers X and Y
60    LET A = X+Y
70    PRINT " VALUE OF X = "; X
80    PRINT " VALUE OF Y="  ; Y 
90    PRINT "ADDITION OF X AND Y = "; A
100  END
Ok
RUN
?   25
?   10
VALUE OF X = 25
VALUE OF Y = 10
ADDITION OF X AND Y = 35
Ok

CS 5.8 Display on the screen for INPUT statement
Ok
LIST 
10    REM Learning the use of INPUT statement
20    INPUT N$
30    INPUT C
40    INPUT A$
50    INPUT R
60    PRINT " MY NAME IS " ; N$
70    PRINT " I STUDY IN CLASS "; C
80    PRINT " MY SCHOOL'S NAME IS "; A$
90    PRINT " MY ROLL NO. IS "; R
100  END
Ok
RUN
?  SUMA SHAH
?  9
? EAST-POLE HIGH SCHOOL
? 26
MY NAME IS SUMA SHAH
I STUDY IN CLASS 9
MY SCHOOL'S NAME IS EAST POLE HIGH SCHOOL
MY ROLL NO IS 26 
         

     
        

Wednesday, June 5

LET statement

The LET statement assigns the value of an expression to a variable.
Syntax
LN [LET] Variable = expression
Where,
LN      :     Line Number
[LET]  :     LET is optional (i.e. the equal sign(=) is sufficient to assign an expression to a variable.
Variable  :  Stores the values of expression on the right hand side.
Expression  valid BASIC expression
Points to remember

  • In the LET statement the type of variable and type of expression must match each other.
  • The LET statement is optional in programs, only the equal sign(=) is sufficient to assign an expression to a variable.
Examples
1. 30 LET X = 20
2. 20 LET N $ = "SUMA SHAH"

CS 5.5 Dislplay on the screen for LET statement

Ok
LIST
10   REM Learning the use of LET statement
20   LET N$ = "SUM SHAH"
30   LET C = 9
40   LET A$ = EAST - POLE HIGH SCHOOL"
50  LET  R = 26
60  PRINT " MY NAME IS " ; N$
70  PRINT " I STUDY IN CLASS ";C
80  PRINT " MY SCHOOL'S NAME IS ";A$
90  PRINT "  MY ROLL NO. IS "; R
100  END
Ok
 RUN
MY NAME IS SUMA SHAH
I STUDY IN CLASS 9
MYS SCHOOL NAME IS EAST - POLE HIGH SCHOOL
MY ROLL NO IS 26
Ok

CS 5.6 Display on the screen for LET statement  

Ok
LIST 
10 REM Learning the use of LET statement
20 REM Values of two numbers X and Y
30 LET X=20
40 LET Y=10
50 REM Addition of two numbers X and Y
60 LET A =X+Y
70 PRINT "VALUE OF X =";X
80 PRINT "VALUE OF Y=";Y
90 PRINT "ADDITION OF X AND Y =";A
100 END
Ok
RUN
VALUE OF X= 20
VALUE OF Y=10
ADDITION OF X AND Y = 30
Ok