View Single Post
Old 01-22-2022, 05:25 AM   #301
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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.
chaley is offline   Reply With Quote