You are on page 1of 12

The Variables

in Small Basic
Lesson 2
Variable
A variable is a storage location that uses a symbolic
name associated with a value. An example is when
you want to create a program that requires saving
data in the computer’s memory. A variable serves
as the container where your inputs are entered. In
Small Basic, variables are the primary method for
moving information around the program.
Rules in naming
You can use a combination of letters,variables
numbers, and
underscores.

The First character must be a letter.

You cannot use keywords reserved by Small Basic.


Integer
It is a type of variable that is used to represent
whole, non-decimal or non-fraction numbers.
For example: 1, 20, 100, 10000.

You cannot use a comma in large numbers.


String
It stores a list of various characters like
names, numbers, sentences, paragraphs or
characters. Strings are always enclosed in
quotes (“ “), for example: “Nickname”, “25”.
Boolean
It is a type of variable that can have one of
two values. For example: true or false.
Primitive
Compared to other programming
languages, Small basic has only one type of
variable called primitive. Its data type can
be transformed between integers and
decimals, strings and arrays as the context
changes. The following two lines create the
same results:
Primitive
Name = jeffrey
Name = “jeffrey”
Jeffrey is assigned to the variable Name. The
actual value assigned to the variable is called
literals.
Assigning a value in a variable is called the
assignment statement. It is the simplest and
most used statement in Small Basic. It uses
the assignment operator to assign a value to
its left operand based on the value of its right
operand.
Here is an example:
sum = value1 + value2
Variables in Expressions

You can store and manipulate numbers in variables


to create programs that deal with computations.
Creating expressions or equations in Small Basic
follows the order of operation PEMDAS, which
stands for Parenthesis, Exponents, Multiplication,
Division, Addition, Subtraction
When several operations take place within the same
equation, some operations are executed before
others. Operations are executed in the following
order:

1. Parentheses or brackets.
2. Exponents and roots
3. Multiplication and division
4. Addition and subtraction
Practice your
PEMDAS
1. 2+2+4+4-10 = 6. 8+(2+1)2 =
2. 2x(3+1) = 7. 2+(6x52+3)=
3. 18/2-4 = 8. 5x5x5+4-10=
4. 8+8-8-8 = 9. 2x3+9/3=
5. 6/3+6x2 = 10. 5+ [-1(-2-1)]2 =

You might also like