Saturday, January 21, 2012

Assigning a value to a Variable

---------------------------------------------------------------------------

If I want to assign a vaule to a variable, I do the following

X = 5;

we say this as "X gets the value 5".

---------------------------------------------------------------------------

If I want to assign the value of X to a new variable Biggest, I do the following

Biggest = X;

we say this as "Biggest gets the value of X".

---------------------------------------------------------------------------

If I want to add two numbers and print out the result, I do the following

X = 5;
Y = 4;
SumOfNums = X + Y;

The following is incorrect:

X + Y = SumOfNums;

---------------------------------------------------------------------------

No comments:

Post a Comment