0% found this document useful (0 votes)
48 views

Introduction to GW

Uploaded by

Sourav Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Introduction to GW

Uploaded by

Sourav Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

INTRODUCTION TO GW – BASIC

GW – BASIC is a High Level Programming language developed by John George


Kemeny and Thomas Eugene Kurtz in the DBASIC stand for Beginners All-purpose Symbolic
Instruction Code, the GW in GW-BASIC stands for Gee Whiz (which means Surprised)
sometimes it is also said that GW is named after Greg Whitten (former Microsoft Chief
Software Architect) who developed the translator for BASIC , New Hampshire U.S. in 1964.
Just like any other programming language BASIC has certain building blocks which are used
to develop programs. Those building blocks are –
 Constants
 Variables
 Operators and
 Commands
Constants – A constant is a term or value that does not change during program execution.
There are two types of constants in GW-BASIC
1. Numeric Constant
2. Alpha-Numeric Constants
Numeric constants are numbers that can be either positive, negative or zero and can also be
fractional numbers expressed with decimal point. E.g. 656, – 26, 3.14, 9.8, 0.0 etc…
Alpha-Numeric Constants also known as String constants is a sequence of valid BASIC
characters enclosed within a pair of double quotes. They may include alphabets, special
characters, numbers or sentences. E.g. “Linkin Park”, “*123#”, “A”, “65536” etc…
Variables – A variable is a memory location to store a constant. The value of a variable can
change during the execution of a program. A variable allocates a space inside the physical
memory of the computer (RAM) to store a value. A variable must start with an alphabet and
can be maximum 8 characters long. There are two types of variables in BASIC –
1. Numeric Variable
2. Alphanumeric Variable
Numeric Variables can store only numeric constants. They can have a maximum length of 8
characters which can be both alphabets and numbers but they must begin with an alphabet
and not a number. E.g. N, VAL1, AREA, G, PI etc…
Alphanumeric Variables are used to store strings, these variables can also have a maximum
length of 8 characters
Alphanumeric Variables are used to store strings, these variables can also have a maximum
length of 8 characters which can be both alphabets and numbers (must begin with an
alphabet) but they must end with a $ sign. E.g. A$, ABC$ N1$ etc…

Operators – These are special symbols that are used for specific purpose. Operators are of 3
different types in BASIC
1. Arithmetic Operators
2. Logical Operators
3. Relational Operators

Arithmetic Operators are used to perform mathematical calculations on numeric quantities.


 + for Addition
 – for subtraction
 * for multiplication
 / for division
 ^ for exponentiation

Priority of Operators in GW-BASIC (High to Low)


 ( ) brackets
 ^ exponentiation
 * multiplication
 / division
 + addition
 – subtraction

Relational Operators are used to perform decision making based on comparison between two
or more quantities.
 < Less than
 > Greater than
 <= Less than or equal to, =< can also be used for the same purpose
 >= Greater than or equal to, => can also be used for the same purpose
 = Equal to
 <> Not equal to

Logical Operators are used to join two or more relational operators in BASIC, There are 3
different types of Logical operators AND, OR, NOT (more of this will be discussed in Chapters
ahead)

System Commands –
NEW – This command is used to start a new program after removing previous ones (if any) from the
primary memory of the computer (RAM)
CLS – This command is used to clear the screen.
AUTO – This command is used to generate automatic line numbers, by default the gap is 10. To
customize the gaps we may use the following format as shown –
EDIT <line number> – This command is used to display any specific line of BASIC program and
correct the errors.
E.g. EDIT 30
The above command will show line number 30 and allow the programmer to edit the same.
LIST – This command is used to display the contents of entire program currently in the primary
memory
Shortcut key: F1
RUN – This command is used to execute the program which is currently residing in the primary
memory
Shortcut key: F2
SAVE – This command is used to save the current program from primary memory (RAM) to the
secondary storage device (Hard Disk)
Syntax: SAVE <filename.bas> (The filename is to be provided within double quotes)
LOAD <filename> – This command is used to load (copy) the program from Hard Disk to primary
memory (RAM)
RENUM – This command is used to re-number the line numbers if they are not in equal intervals
Syntax: RENUM
DELETE <line numbers> – This command is used to delete a line of code from the current program
residing in (RAM)
e.g. DELETE 30
The above command will delete line number 30 from the current program.
KILL <filename> – To delete a program file permanently from Hard Disk
LET Command
In GW-BASIC assignment can be done using LET command as well as direct assignment of
variables without using the LET command. The word assignment means “to store”. Both the
examples are shown below.
Syntax:
LET <variable> = <value>
LET A = 10
PRINT A

PRINT Command
This command is used to generate the output on the screen.
Syntax:
PRINT <list of expression>
If <list of expressions> is omitted, a blank line is displayed.

INPUT statement in GW-BASIC

The Purpose of an INPUT statement is to prepare the program for input from the terminal during
program execution.
INPUT “Enter your age” ; A

Mathematical Functions in GW-BASIC


GW BASIC has provided programmers with an extensive collection of in–built Library functions, This
chapter deals with the most commonly used Mathematical functions.
SQR (n): This function returns the square root of n.
Syntax: SQR(n)
INT (n): This function is used to truncate an expression to a whole number.
Syntax: INT(n)
Comments:
Negative numbers return the next lowest number.
ABS (n): This function is used to return the absolute value of the expression ‘n’.
Syntax: ABS(n)

IF … THEN … ELSE statement in GW-BASIC


In GW BASIC IF…THEN…ELSE is used to make a decision regarding program flow based on the
result returned by an expression and conditionally branch or take necessary action .
Syntax:
IF <expression> THEN <statement(s)> ELSE <statement(s)>
If the result of expression is nonzero (logical true), the THEN or GOTO line number is executed.
Multiple if conditions can be joined together using LOGICAL operators like AND & OR. There can be
practically infinite number of AND & OR to connect the relations.
INPUT “AGE”; A

IF A>=13 AND A<=19 THEN DISPLAY “TEENAGER” ELSE PRINT “NOT A TEENAGER”

You might also like