Quote:
Originally Posted by ownedbycats
That works. I didn't realize it was possible to re-use a variable name and have it return different things. That will be useful to know.
|
Ahhh, that explains some of your previous questions.
A variable is a container, not an alias. You set or change the contents of a variable by assigning to it. A copy is made of the result of computing the expression on the right-hand side of the '=' then then stored in the variable named on the left-hand side of the '='. The right-hand expression is evaluated before assignment so assigning to a variable doesn't affect the result of the expression. And vice versa, you can change anything that was used in a previous expression without changing what was stored in the variable.
Examples:
Code:
x = 5;
# x contains the value 5.
y = x + 1;
# y contains 6 (5 + 1). x still contains 5.
x = x + 10
# x contains 15 (5 + 10). y still contains 6.
y = x + 1;
# y contains 16 (15 + 1). x still contains 15.
y = (x + y) * 2;
# y contains 62 ((15 + 16) * 2). x still contains 15.
y = x;
# y contains 15. x still contains 15.
y = y + 1
# y contains 16. x still contains 15.