Assignment Statement

Programs can have many variables. Usually information is gathered from the user, stored in variable, processed with other variables, saved back to one/some variable(s) and then returned to the user. Variables are changed or initially assigned a value by the use of an assignment statement. Assignment statement are usually written in reverse from what we are use to in math class. A variable on the left side of the assignment statement will receive the value that is on the right hand side of the assignment statement. Note that different programming languages use different symbols to represent the assignment statement (for example in Alpha it is” ←”, in Pascal it is” :=”). No matter what the symbol is, you always read it as, “is assigned”. This is particularly important in languages like Visual Basic, where the assignment symbol is an equal sign ( = ) and people are use to reading this as “is equal to”. C# also uses and equals sign ( = ) as its assignment operator. To make it even more confusing, the same symbol ( = ) is used in another context in Visual Basic and in that one it actually is an equal sign and is read as such. In C# the equals symbol is actually two equals signs next to each other (==). Here are a few examples of assignment statements:

// assignment statement
numberOfStudents = numberOfStudents + 5;
width = 32;
length = 10;
areaOfRectangle = length * width;
someWords = "Hello, Wordl!";
// assignment statement
numberOfStudents = numberOfStudents + 5
width = 32
length = 10
areaOfRectangle = length * width
someWords = "Hello, Wordl!"
// assignment statement
numberOfStudents = numberOfStudents + 5;
width = 32;
length = 10;
areaOfRectangle = length * width;
someWords = "Hello, Wordl!";
// assignment statement
numberOfStudents = numberOfStudents + 5;
width = 32;
length = 10;
areaOfRectangle = length * width;
someWords = "Hello, Wordl!";
# assignment statement
number_of_students = number_of_students + 5
width = 32
length = 10
area_of_rectangle = length * width
some_words = "Hello, Wordl!"
# assignment statement
number_of_students = number_of_students + 5
width = 32
length = 10
area_of_rectangle = length * width
some_words = "Hello, Wordl!"
// assignment statement
numberOfStudents = numberOfStudents + 5
width = 32
length = 10
areaOfRectangle = length * width
someWords = "Hello, Wordl!"