You are on page 1of 11

Programming and Basics

LOOP
While writing a program it is necessary to repeat a part of a program for a number of times. The
best solution for this is to use a loop it is a method which executes a part of the program
repeatedly as specified by the programmer.
TYPES OF LOOPS
a) Pre-Test Loop
b) Post-Test Loop
a) PRE TEST LOOP
As its name indicates, checs the looping condition at the start of the loop if the condition is true
the loop execution starts otherwise stops. This loop is used in a situation when part of program is
to be repeated for a fixed number of time.
e.g., !"# $$ %&'T.
b) POST TEST LOOP
This loop checs the looping condition at the end of loop and decides whether or not to continue
the execution. This loop is used when a part of the program needs to be repeated until a specified
condition is met.
e.g., W()L& $$ W&%*.
FLOW CHART
!low chart is a symbolic representation of flow of programme. )t can graphically represent data
processing procedure !low chart ser+es two purposes, i.e., the planning of the program structure
as an aid in writing the computer program. ,econdly the documentation of the program logic and
wor flow for the purpose of the communication with other person and to recall a program at a
later time. )f the program needs to be changed. The second purpose is +ery important because it
is +ery difficult to chec the logic of the program.
SYMBOLS OF FLOW CHART
TERMINAL
The terminal symbol is used to indicate the beginning, ending of the program logic flow. )t is the
first and last symbol of the flow chart.
INPUT / OUTPUT BOX
The input-output box is used to denote any function of an input and output in the program. )f
there is a program instruction to input or output the data from any )-" de+ice that step will be
indicated on this symbol.
PROCESS BOX
A processing symbol is used in a flow chart to represent arithmetical and data mo+ement
instructions.
FLOW LINES
!low lines are used to indicate the flow of operations. The exact se.uence in which the
instructions are to be executed. The flow of flow chart is normally from top to bottom and left to
right.
DECISION BOX
The decision box is used in a flow chart to indicate a point at which a decision has to be made
and to branch to one or more alternati+e points that is possible during execution. The appropriate
path followed, depends on the result of the decision.
CONNECTOR
A flow chart becomes complex, when the number and direction of flow lines is confusing or it
spread o+er more than one page. )t is useful to utili/e the connector symbol as a substitute for
flow lines.
SYSTEM FLOW CHART
,ystem !low 0hart is used to describe complete data processing cycle including the hardware
de+ices and media used. A ,ystem !low 0hart shows flow of data in a system where and in what
form it is recei+ed by the system, how it is input to the computer and what storage media are
used to hold it. The symbol used in system flow chart indicates the peripherals to be used in data
processing procedure, where output will be produced. ,ystem flow chart do not explain the logic
of the programs.
ERRORS
&rrors are the mistaes made by the programmer during program writing. A program relays run
perfectly for the first time and each program needs to be tested to ensure that it is correct and
contains no errors. There are three types of errors generally encountered.
a) ,yntax &rror
b) Logical &rror
c) #un Time &rror
a. SYNTAX ERROR
The syntax of a programming language is the set of rules to be followed when writing a program
in that language. These rules are similar to the grammar rules of 1rdu or &nglish language.
When a program +iolates these rules, computer generates a syntax error. ,yntax must be correct
before program execution.
b. LOGICAL ERROR
These errors are the most difficult ones to find, if a programmer enters a sign of multiply instead
of addition at the time of maing the program, the answer will not be correct because interpreter
will not be able the detect these types of errors. A logical error will not stop the execution of the
program but the result will not be accurate.
c. RUN TIME ERROR
These types of errors stop the execution of the program. )t may be due to entering the in+alid
data at the time of executing a program. !or example, if a program is expecting the user to enter
the numeric data and the user enters a string data, computer will display an error message.
BITS & BYTES
The smallest piece of data that can be recogni/ed and used by a computer, is the bit, a binary
digit. A bit is a single binary +alue, either a 2 or 3. A group of eight bits is called a byte. The byte
is the basic unit for measure of the si/e of the memory, with today4s computer memory si/es. )t
is more common to hear the term ilobyte 567) or megabyte 587).
COMPUTER WORD
A computer word is the number of ad9acent bits that can be stored and manipulated as a unit. :ust
an &nglish +ocabulary words are of +arying lengths so are computer words. 8any
microcomputers ha+e the ability to manipulate a ;< bit word, while some models ha+e words
length of = and 2> bits.
LIBRARY FUNCTIONS
?W-7A,)0 pro+ides many built in functions which are called binary functions. &ach function is
composed of a format or a short program, that re.uires at least one parameter to be passed. A
parameter is a +alue which is in that formula or program and this formula or program returns a
result. This result can be stored in any appropriate +ariable or directly displayed on monitor. A
library function which has @AB sign is called string library function while others are called
numeric library function. A string function returns string +alue while a numeric function returns
numeric +alue. !ollowing are some library functions.
A7,, 8)*A, L&%, L&!TA, A,0, 0(#A, TA7
EXPRESSIONS
An expression is a combination of constants and +ariables lined by arithmetic operators lie 5C,
-, D, -, E). &xpressions are used to perform different operations. The expressions are e+aluated
from left to right but some operators ha+e priority o+er the others. Parenthesis are e+aluated first
then multiplication and di+ision ha+e the same priority from left to right. ,imilarly the addition
and subtraction are e+aluated with e.ual priorities. )f all the operators are used in an expression
ha+e the same priority then the expression be executed from left to right.
The expressions can be of three types.
Arithmetic expressions
Logical expressions
#elational expressions.
ARITHMETICAL EXPRESSIONS
)n an arithmetic expression the following operators are used in con9unction with the operands.
,ymbol8eaning
C Addition
- ,ubtraction
8ultiplication
- *i+ision
F &xponentiation
5 Left parenthesis
) #ight parenthesis
RELATIONAL EXPRESSION
A #elational expression is composed of operands lined by the relational operators. The
relational operators used in the relational expression are gi+en.
,ymbol8eaning
G e.ual to
H greater than
I less than
IH not e.ual to
HG greater than or e.ual to
IG less than or e.ual to &xample A H 7
7 IH 0
LOGICAL EXPRESSIONS
When a selections is based upon one or more condition being true. )t is possible to combine the
condition together using logical operators and the resulting condition would either be true or
false the most commonly used logical operators are A%*, "# and %"T.
COMPUTER LANGUAGE
Language is a system for representation and communication of information or data. Lie human
beings, a language or signal is re.uired to communicate between two persons. ,imilarly, we
cannot obtain any result by computer without langtage. 0omputer does not understand directly
what we are communicating with computer as &nglish or Arabic, it understands only machine
language 5binary codes 3-2). 0omputer translates &nglish language into machine codes through
interpreter then process instructions and gi+e us the results.
The computer languages can be di+ided into two main le+els.
8achine language 53-2)
,ymbolic language 5A-J)
,ymbolic languages are further di+ide into two main le+els
(igh-le+el language
Low-le+el language
MACHINE LANGUAGE
Although computers can be programmed to understand many different computer language. There
is only one language understood by the computer without using a translation program. This
language is called the machine language or the machine codes. 8achine codes are the
fundamental language of the computer and is normally written as strings of binary 3-2.
ADVANTAGES AND LIMITATIONS OF MACHINE LANGUAGE
Programs written in machine language can be executed +ery fast by the computer. This is mainly
because machine instructions are directly understood by the 0P1 and no translation of program
is re.uired.
(owe+er, writing a program in machine language has se+eral disad+antage.
MACHINE DEPENDENT
7ecause the internal design of e+ery type of computer is different from e+ery other type of
computer and needs different electrical signals to operate. The machine language also is different
from computer to computer.
DIFFICULT TO PROGRAM
Although easily used by the computer, machine language is difficult to program. )t is necessary
for the programmer either to memori/e the do/ens of code number for the commands in the
machine4s instruction set or to constantly refer to a reference card.
DIFFICULT TO MODIFY
)t is difficult to correct or modify machine language programs. 0hecing machine instructions to
locate errors is difficult as writing them initially.
)n short, writing a program in machine language is so difficult and time consuming.
SYMBOLIC LANGUAGES
)n symbolic languages, alphabets are used 5a-/). symbolic languages are further di+ide into two
main le+els.
(igh le+el languages
Low le+el languages
LOW LEVEL LANGUAGE
A language which is one step higher than machine language in human readability is called
Assembly Language or a low-le+el language. )n an assembly language binary numbers are
replaced by human readable symbols called mnemonics. Thus a low-le+el language is better in
understanding than a machine language for humans and almost has the same efficiency as
machine language for computer operation. An assembly language is a combination of mnemonic,
operation codes and symbolic codes for addresses. &ach computer uses and has a mnemonic
code for each instruction, which may +ary from computer to computer. ,ome of the commonly
used codes are gi+en in the following table.
0"88A%* %A8&8%&8"%)0
Add K A**
,ubtract K ,17
8ultiply K 81L
0ompare #egistry K 0#
0ompare K 0"8P
7ranch 0ondition -70
0ode #egister -L#
8o+e 0haracters -8L&
,tore 0haracters -,T0
,tore Accumulator K ,TA
An assembly language is +ery efficient but it is difficult to wor with and it re.uires good sills
for programming. A program written in an assembly language is translated into a machine
language before execution. A computer program which translates any assembly language into its
e.ui+alent machine code is nown as an assembler.
HIGH LEVEL LANGUAGE
A language is one step higher than low-le+el languages in human readability is called high-le+el
language. (igh K le+el languages are easy to understand. They are also called &nglish oriented
languages in which instruction are gi+en using words. ,uch as add, subtract, input, print, etc.
high le+el language are +ery easy for programming, programmer prefer them for software
designing that4s why these languages are also called user4s friendly languages. &+ery high le+el
language must be con+erted into machine language before execution, therefore e+ery high le+el
language has its own separate translating program called compiler or interpreter. That4s why
some time these languages are called compiler langauges. 0"7"L, 7A,)0, PA,0AL, #P?,
!"#T#A% are some high le+el languages.
INTERPRETER
An interpreter is a set of programs which translates the high-le+el language into machine
acceptable form. The interpreters are slow in speed as compared to compilers. The interpreter
taes a single line of the source code, translates that line into ob9ect code and carries it out
immediately. The process is repeated line by line until the whole program has been translated
and run. )f the program loops bac to earlier statements, they will be translated afresh each time
round. This means that both the source program and the interpreter must remain in the main
memory together which may limit the space a+ailable for data. Perhaps the biggest drawbac of
an interpreter is the time it taes to translate and run a program including all the repetition which
can be in+ol+ed.
PROGRAM DEVELOPMENT PROCESS
)n order to de+elop a computer program, a programmer has to go through the following stagesM
1. DEFINING AND ANALYSING THE PROBLEM
)n this step a programmer studies the problem and decides how the problem will be best sol+ed.
,tudying a problem is necessary because it helps a programmer to decide aboutM
The facts and figures to be collected.
The way in which the program will be designed.
The language in which the program will be most suitable.
What is the desired output and in which form it is needed, etc.
. DESIGNING THE ALGORITHM
An algorithm is a set of instructions or se.uence of steps that must be carried out before a
programmer starts preparing his program. The programmer designs an algorithm to help
+isuali/e possible alternati+es in a program.
!. FLOWCHARTING
A flow chart is a graphical representation of a program which helps a programmer to decide on
+arious data processing procedures with the help of labeled geometrical diagrams. A flow chart
is mainly used to describe the complete data processing system including the hardware de+ices
and media used. )t is +ery necessary for a programmer to now about the a+ailable de+ices
before de+eloping a program.
". CODING OR WRITING THE PROGRAM
The next 9ob after analysing the problem is to write the program in a high-le+el language, usually
called coding. This is achie+ed by translating the flow chart in an appropriate high-le+el
language, of course according to the syntax rules of the language.
#. TEST EXECUTION
The process of execution of any program to find out for errors or bugs 5mistaes) is called test
execution. This is +ery important because it helps a programmer to chec the logic of the
program and to ensure that the program is error-free and worable.
$. DEBUGGING
)t is a term which is used extensi+ely in programming. *ebugging is the process of detecting,
locating and correcting the bugs by running the programs again and again.
%. FINAL DOCUMENTATION
)t is written information about any computer software. !inal document guides the user about how
to use the program in the most efficient way.
MODES OF OPERATION
There are two modes of operation for 7A,)0. The mode that you are in determines what 7A,)0
will do with the instruction you gi+e it. When you start 7A,)0 you recei+e the "6 prompt. Nou
then ha+e two modes a+ailable to you immediately.
DIRECT MODE
)n the direct mode 7A,)0 acts lie a calculator. %o line numbers are re.uired. *irect mode is
not of course the main purpose of 7A,)0, but it is useful at times particularly when you are
debugging program or short problems in which you want to perform .uic calculation e.g.,
P#)%T ;CO.
INDIRECT MODE
)n this mode you first put a line number on each statement. "nce you ha+e a program you can
run it and get your results. The indirect mode sa+es your instructions in the computer along with
their line number, you can execute the program as many times as you wish simply by typing
#1%.
STEPS OF PROGRAMMING
There are fi+e steps in preparing a computer programme which are also called A70*& of
Programming.
ANALYSIS
)n this step the system analyst tries to become familiar with the problem. (e has to study the
problem and prepare some notes upon that problem. (e also notes that what is gi+en, what is
re.uired and what will computer can do.
BLOC&ING
)n this step the programmer con+erts the analyst report to a series of steps through which the
computer will gi+e the re.uired result. The steps are commonly nown as Algorithm. There are
different ways to write those detailed se.uential steps. The most common method used is flow
charting. A flow chart is symbolic representation of flow of a programme.
CODING
)n this step the programmer writes the programme in any computer language. This step is nown
as coding. After this programme is fed into the computer and is compiled with the help of a
gi+en compiler.
DEBUGGING
*ebugging is a step in which a programmer corrects a syntax error which may come after the
compilation.
TESTING
Testing is a step where the programmer is finally testing the programme for execution 5there may
be any logical mistae which compiler cannot trace).
EXECUTION
)n this step we send the programme for execution where company4s data will be fed and process.
VARIABLES AND CONSTANTS
VARIABLES
Lariables are names used to represent +alues used in 7A,)0 programme. The +alues of a
+ariable may be assigned by the programmer or it may be assigned as the result of calculation in
the programme. 7efore a +ariable is assigned a +alue is assumed to be /ero 5or null for string
+ariable).
VARIABLES NAMES ' DECLARATION CHARACTERS
Lariable names may be of any length up O3 characters are significant. Lariable name can contain
letters, numbers and decimal point. (owe+er, the first character must be a letter. A +ariable
should not be a reser+e word.
Lariable may represent either a numeric +alue or a string.
NUMERIC VARIABLE
%umeric +ariable names may be declared as integer, single precision, double precision +alues.
The type of declaration characters for these +ariable names are as follows.
STRING VARIABLE
)n programming we often use to handle alphanumeric or string +ariables. ,tring +ariables consist
of names, addresses or in general any string or series of letters, number or special characters.
Without the use of string +ariable whene+er any differentiation needs to be made e.g., from
employee to employee or from application no. to application no., a number has to be assign to
each employee or each application.
A string +ariable name starts with an alphabet and terminate with a dollar sign 5A). )n a string the
+alue must be in .uotation mars. %o arithmetic operations except addition and in addition the
+alues do not add they are 9ust written together. The maximum number of character allowed in a
string +aries from system to system but a typical +alue is <P>.
CONSTANTS
0onstants are those that do not change while executing the programme. 7A,)0 deals with two
types of constant.
2. %umeric constant
<. ,tring constant
1. NUMERIC CONSTANT
All numbers belong to this category because their +alues remain constant during execution.
They may tae any of the following formsM
2. 0ommas are not allowed in a numeric constant.
<. The use of the positi+e sign is optional but negati+e sign should be used if the number is
negati+e.
. STRING CONSTANT
A string constant is any set of +alid basic characters enclosed in .uotation mars. The .uotation
mars do not form part of string. ,trings are used to represent non-numeric information suchM
2. %ame of persons and places
<. Addresses
;. *ays, 8onths, Nears.
INTRODUCTION TO BASIC
7A,)0 is a high le+el language used for purpose of writing a program on a computer. )t stands
for 7eginners All-purpose ,ymbolic )nstruction 0ode. 7A,)0 is an easy to use @friendlyB
language where instruction resembles elementary, algebraic formulas and certain &nglish
eywords such Let, #ead, Print, ?oto etc.
HISTORY OF BASIC
The language was de+eloped at *artmouth 0ollege in 2Q>R, under the direction of :ohn 6emeny
and Thomas 6urt/. )t was .uicly disco+ered and adopted. All the ma9or computer
manufacturers offered their own +ersion of 7A,)0 for their particular computers.
)n 2QR=, the American %ational ,tandard )nstitute standardi/ed an essential subset of 7A,)0 in
order to promote uniformity from one +ersion of 7A,)0 into another.
)n recent years some new +ersion of 7A,)0 ha+e been de+eloped which included a +ariety of
features that are not included in more traditional +ersions.
STRUCTURE OF BASIC PROGRAM
&ach instruction in a 7A,)0 program is written as a separate statement. Thus a program will be
composed of a se.uence of statements.
The following rules apply to all 7A,)0 statementsM
2. &+ery statement must appear on a separate line number.
<. &ach statement number must be followed by a 7A,)0 eyword which indicates the type of
instruction.
;. "n one single line number we cannot write two statements, if we need we must use @colonB.
O. We can write <PP characters on one line.

You might also like