The
"Assignment Statement"
< Back >
Assigns a value to a variable to be stored in memory,
for use later in a program
To use an assignment statement in a program to store
some value :
1.
write the variable you want,
2.
type the “equal” sign (“=”)
3. then type value or expression
you want to save
i.e: y = 5 + 2
The program will evaluate
the expression
on the right side of the equal sign (“=”)
and store that value into the variable on the
left side of the equal sign.
Assignment statements like “x = 12" and "y
= 7"
store values into the computer's memory
so that the program can use them later.
and evaluating the expression in a PRINT statement :
‘ Program to add 2 values stored
in variables :
x = 6 + 6 '
x is the variable you want
to have the value 12 (the program adds 6 + 6 and stores the result)
y = 5 + 2 ' y is the variable you want to have the value 7 (the program adds 5 + 2 and stores the result)
PRINT x +
y ' Look up what’s stored in x
and y, add them together to display the answer
After assigning values to x and y, the program can PRINT the sum of the
values that are stored there.
Since x has the value 12 (6 + 6) and y has the value 7
(5 + 2),
the PRINT statement displays the answer : 19 on the display screen.
Example :

The
statement “Total = UnitPrice * Quantity” may look
like
an algebraic “statement of equality,”
but is
actually an “assignment statement.”
These are not the same thing.
Programming Assignment
Statement
In programming languages, the statement “X = 5” is an instruction :
This looks up the value on the right side of the equal sign (5)
and then assigns (stores) it into the variable on the left side of the equal
sign.
Algebraic
Statement of Equality
both sides of the equal
sign are equal to each other.
X
= Y is
the same as Y = X
<
Back >