BASIC is a popular programming language for the beginners. It was developed in 1964. Using this easy language, we can make very interesting programs with text and graphic output.
A number of companies provide this language under different names.
For example,
T-BASIC, GW-BASIC AND Q-BASIC.
1. Structure of a Program in BASIC language:
A number of companies provide this language under different names.
For example,
T-BASIC, GW-BASIC AND Q-BASIC.
1. Structure of a Program in BASIC language:
- Every program in BASIC language has a line number. The line numbers start from 10 and increase with the difference of 10. For example, 10,20,30,...
- Every line in the programme is called a statement. This statement asks the computer to perform the required task.
2. Our First BASIC Program:
Using BASIC, we can print any message on the screen. To display a message, we use the PRINT statement. This statement takes a message from us and prints it on the screen. Type the following PRINT statement and press ENTER.
10 PRINT "Hello, World!"
140 END
Our first program will give this output on the computer screen.
3. Modes of a Program:
In BASIC, we can write a programme in two different modes.
(i) Direct Mode
(ii) Indirect Mode
(i). Direct Mode:
In the direct mode, we can write any program and immediately run it without giving any line numbers or saving to the floppy or hard disk. Our first programme was also written in the Direct Mode.
Here is another Direct Mode program.
PRINT 4+2 <Enter>
we will get this output on the computer screen.
(ii). Indirect Mode:
In the Indirect Mode we can write multilane programs and then run all the statements turn by turn. We can also save these programs on the floppy or hard disk.
Write the following program with line numbers.
10 PRINT "I Live in"
20 PRINT "USA"
Now type RUN and we get the output on the screen.
4. Saving a Program:
To save a program on floppy disk, type the following command.
SAVE " my prog1" <Enter>
5. Loading a Program:
Loading a program means getting data from the floppy disk to the computer, so that we may run it. Use this command to load a program from floppy to the computer.
LOAD " my prog1" <Enter>
6. Getting List of the Loaded Programs:
LIST command in BASIC displays all the programs that have been loaded in the computer memory and can be run by RUN command.
LIST " my prog1" <Enter>
7. Variables in BASIC:
BASIC language allows us the use of variables. Therefore, instead of using constants as in our previous examples, we can use variables in our programs. Once defined, we can store values in these variables and can use them anywhere in the program.
8. Variable Types In BASIC:
We can use two types of variables in BASIC:
a. Numeric
b. String
a. Numeric Variables:
Numeric Variables can hold numeric values. For example, 12,32,23,50 etc. We can perform calculations on numeric variables.
b. String Variables:
String variables can store non-numeric data. For example, David, USA, A, 77%, etc.
9. Using Variables:
To use a variable, whether it is numeric or string, we have to take two steps:
a. Defining the Variableb. Defining a String Variablea. Defining a Numeric Variable:
In BASIC, a numeric variable can be defined in this way.
LET A=20
In the above statement, we use LET to define a variable 'A' and give it the value 20. We can give any numeric value to a variable.
b. Defining a String Variable:
A string variable is the collection of alphabets. Defining a string variable is a little different to defining a numeric variable. Let us see how?
LET B$ = "Computer"
Note: A string variable may also contain numbers but a numeric variable cannot contain alphabets. (Every string value for a variable should be in double quotes).
For example, the following two statements are correct.
LET C$ = "123"LET D$ = "A1B2C3"
In the above example, both '123' and 'A1B2C3' are taken as string values and stored into string type of variables.
10. BASIC Commands:
You already know about some BASIC commands, such as SAVE, LOAD, SAVE and RUN. Let's know some other commands.
- BASIC or GWBASIC (This command is used to load BASIC language itself. This command will work when you are in the directory that contains the BASIC OR GWBASIC file).
- SYSTEM (We use this command to exit from BASIC language environment)
- INPUT (This command is used to get input from user. This input is stored into some variable).
- CLS (This command is used to clear the monitor screen).
- END (End is used to end a BASIC program. This statement comes at the end of a program).
Program - 1
Now we make some program that gets two values from the user: stores them into the variables and shows the total of the two values to the user.
10 CLS 20 INPUT "Enter first Value"; A
30 INPUT "Enter second Value"; B
40 PRINT A + B
50 END
No comments:
Post a Comment