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

Introduction to Basic

Uploaded by

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

Introduction to Basic

Uploaded by

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

THE BASIC CHARACTER SET

• This is the collection of all characters recognized by BASIC.


Bellow is a table showing the fundamental characters sets
used in BASIC:
CHARACTER SET SYMBOL

Alphabets A-Z

Numeric 0-9
THE BASIC CHARACTER SET

Grouping characters Comma, colon, semi colon, single


and double apostrophe,
parentheses,

Comparison operators Equal (=), not equal (<>), greater than


(>), less than (<)

Common arithmetic operators =, +, *, /, ^


RESERVED WORDS

A reserved word also known as a reserved identifier, is a word a word


in programming language that has a specific meaning.
It cannot be redefine or use in any other way then the one intended
by the language creator.
Example of reserved words include if, else, const, and goto
Reserved words are fundamental building blocks of any
programming language. Reserved words can be use to create the
structure, flow, and behavior of a program.
RESERVED WORDS

Reserved words can also be used to define the data type in a


program. Example is the reserved word int used to denote
integer numbers. Reserved words can also be used to define
the scope of variables and functions such as private and public
in some languages.
IMPORTANCE RESERVED WORDS

Reserved words plays important role in program compilation


and execution. The compiler or interpreter uses reserved
words to understand the structure and flow of the program.
Reserve words are used to generate machine code that the
computer can execute.
Without reserved words, the compiler or interpreter wouldn’t
have a way to understand the intent of the program.
IMPORTANCE RESERVED WORDS

Reserve words help to prevent errors in the code. For instance,


the compiler or interpreter will generate an error if a
programmer mistakenly uses a reserve word as a variable
name. in this way the programmer get an alert for the mistake
KEYWORDS

Keywords in computer programming are predefine


words in programing language with a specific use.
They are used to define structure and flow of a
program. Also, they specify the operations that the
program should perform. Some keywords are int,
break, this, and static.
IMPORTANCE OF KEYWORDS

Keywords are important for several reasons:


1. It improve search engine rankings. Businesses can improve their search
engine ranking by including relevant keywords in website content.
2. targeted advertisement. Keywords are also used in pay per click
advertising campaign to target a specific audience/customers.
3. Increase website security: by including keywords in blog post and other
type of content, business can attract more traffic to their website.
4. effective e-commerce.
DATA TYPES

In programming, data type refers to the type of value


a variable has and what type of mathematical,
relational or logical operations can be applied without
causing an error. For example, many programming
languages use the data type string to classify text,
integer to identify whole numbers and floating point
to designate numbers with decimal points.
DATA TYPES
Data Type Use for Example

String Alphanumeric characters Hello world


Nakita
Joe123
Integer Whole numbers 5
10
987
Float(Floating point) Numbers with decimal points 2.123
8.245
0.456

Character Encoding text numerically 97(in ASCII, 97 indicate a lower


case a)
Boolean Representing logical value True
False
DATA TYPES

The data type defines which operations can safely be performed


to create, transform and use the variable in another
computation. In most programming languages, variable values
commonly possess a static type. However, the values of those
static types can still exist within multiple variable classes. While
some classes specify how the data type's value will be compiled
or interpreted, there are other classes whose values are not
marked with their class until runtime.
DATA TYPES

The extent to which a programming language discourages or


prevents type error is known as type safety. When a
programming language requires a variable to be used only in
ways that respect its data type, that language is said to be
strongly typed. If data types do not align such as trying to
multiply an integer by a string a strongly typed language will
likely prevent the program from running to avert potential
operational errors.
IDENTIFIERS

Identifiers are names given to a variable on which


data operations are to be carried out.
You could refer to identifiers as variable name or data
name.
Example: Let T= A+B+C
RULES FOR NAMING IDENTIFIERS

1. A valid identifier can have letters (both uppercase and


lowercase letters), digits and underscores.
2. The first letter of an identifier should be either a letter or an
underscore.
3. You cannot use keywords like int, while etc. as identifiers.
4. There is no rule on how long an identifier can be. However, you
may run into problems in some compilers if the identifier is longer
than 31 characters.
STATEMENTS

A Statement is a program of code to execute an action.


Statements are of different categories.

INPUT/OUTPUT : This allow for transfer of data or information


between the computer and the various I/O devices.
Input statement is one of the ways of suppling data into the
computer
STATEMENTS

The general syntax is of the form:


Line number input (list of variables separated by
commas)
Example of an input statement is:
INPUT ‘’ Please supply the values of X,Y and Z
separated by commas’’; x,y.z
STATEMENTS

1. REM a program to evaluate the expression X*Y+Z^4-2


2. INPUT ‘’ Please supply the values of X,Y and Z
separated by commas’’; x,y.z
3. LET A= Z^4
4. LET B=X*Y
5. LET C= A+B-2
STATEMENTS

6. PRINT C
7. END

PRINT STATEMENT: This allows a sequence of identifiers values


to be printed.
The general syntax is:
Line Number PRINT (List of identifiers, separated by commas)
STATEMENTS

The PRINT statement is the statement number 6 in the


program.
VALUES OF STRING CAN BE PRINTED AS:
LET K1$= “MY NAME IS”
LET K2$= “LINCOLN IBRAHIM”
PRINT K1$, K2$
END
ASSIGNMENT STATEMENTS

This is used to assign a value to a variable/constant. It


is also used to assign an expression to a variable.
LET Statement.
The general syntax is:
Line number LET variable/constant =
variable/expression
READ AND DATA STATEMENTS

The read statement is used to assign values to identifiers.


The list of values to be read into the computer with a READ
statement will be called data list.
The general syntax is of the form:
Line Number READ (Data List)
READ is a keyword and data list contains one or more
identifiers separated by commas.
READ AND DATA STATEMENTS

Every READ statement must have a correspondent


DATA statement. A value or number is read from the
DATA statement and assigned to an identifier when the
READ statement is executed.
In the example below statement number 1 and 4
respectively illustrate the READ and DATA statements:
READ AND DATA STATEMENTS

1. READ A,B,C
2. LET Q= A+B-C
3. LET P=Q*A
4. DATA 10,20,30
5. PRINT Q,P
6. END.
REM STATEMENTS

BASIC interpreter does not execute the REM statement. It is


just like a comment in in other programming languages. It
give information about probably the name of the program,
purpose of the program, name of the programmer, the day
in which the program was written, etc.
The syntax is:
Line number REM expr.
END STATEMENTS

The END statement informs the computer that all


necessary instructions have been executed.
The syntax is:
Line number END
ARITHMETIC OPERATIONS

This is used when arithmetic calculation to be performed. These


includes assignment, exponentiation, division, multiplication,
subtraction and addition.
OPERATION PRECEDENCE: This refers to the order in which
arithmetic operations are performed. Example; y^4+2+y-9.
This expression involves several operations and certain
precedence must be followed. The order is given by the
expression BEDMAS
CONTROL STATEMENTS

REPETITION
A program may be design to perform more than one task. An example
is calculating the GPA of each student studying CSC 103. In order to
calculate the GPA for more than one student, we would have to execute
the program for more than once. This process will have to be repeated
again and again for a specific number of times. You must know how to
program a loop in order to repeat the calculations. You also know how
to exit from a loop. You must lean conditions in order to loop and exit
from loom.
CONDITIONS

A condition is a logical expression which compare two


numeric or two string expressions. A condition is either
true or false.
Relational operators are used to compare two
expressions. Examples includes equal to, less than,
Greater than, less than or equal to, Greater than or equal
to, not equal to.
THE DO…..LOOP STATEMENT

One way to create a loop in BASIC is to use the do statement and the
loop statement. The DO statement indicate the top/start of the loop
and the loop statement indicate the bottom/end of the loop.
The DO and LOOP statements can be written in several ways as
illustrated below.
DO WHILE LOOPS
Syntax
DO WHILE condition
THE DO…..LOOP STATEMENT

Statement(s)
LOOP
DO UNTIL LOOPS
Syntax
DO UNTIL condition
Statement(s)
LOOP
THE FOR…..NEXT LOOP

A loop that uses a counter to control the number of times it is executed is


called a counter controlled loop. The FOR and Next statements are used
to create such loops. like the DO and LOOP statement, the FOR and NEXT
statements are always used together to define a counter control loop.
Syntax for For statement
FOR counter variable= Initial value to final value (STEP step-size)
Syntax for the Next statement
NEXT counter variable.
DECISIONS

There may be the need for programs to give more than one output base on
some conditions that change in run-time. In such cases conditional
statements are used. Some of the common conditions are discussed below:
The If statement
IF condition THEN
Statement(s) to be executed if condition is true
Else statement(s) to be executed if condition is false
END IF

You might also like