Expressions

Expressions are another way to assign a value to a variable. An expression is a statement that uses a combination of values, variables, operators, and functions to return a calculated value, often assigning it to a variable.

Expressions which assign a value to a variable revolve around the equal sign. Thus, the following expression assigns the value 5 to the variable X:

X = 3 + 2

Here are some other examples:

X = 3 - 2
Y = 4 / 2
Z = (3 + 2)*3

The previous statements would evaluate to the following:

X = 1
Y = 2
Z = 15

Here's another example of an expression:

X = "Hello"
Y = " World"
Z = X + Y

Of course, Z would equal "Hello World".

The symbols such as the equal sign, addition, subtraction, multiplication, and division signs are called operators. They, in a sense, operate on the values of the expression. The parentheses are operators, too. Here are some of the operators thinBasic uses:

Addition +
Subtraction -
Multiplication *
Division /
Exponentiation ^
Integer Division \
Equality =
Inequality <>
Less Than <
Greater Than >
Less Than or Equal To <=
Greater Than or Equal To    >=
NOT
AND
OR
(Exclusion) XOR

You may have noticed that some of these operators are words. These operators as well as some others will be discussed in further detail in another lesson.

Expressions can also be used to help the program make decisions, which will be discussed in the following lesson.