ExpressionAssignsDRAFTObserved

An expression that reads a variable also updates its value after the evaluation
A variable is only written using an assignment
CorrectionHere is what's right.
Students might mistakenly believe that reading from a variable score
within an expression score + 10
also updates the value of the variable (score in this case).
For example, they might believe that the following code outputs the three numbers: 4, 14, and 14.
int score = 4;
System.out.println(score);
System.out.println(score + 10);
System.out.println(score);This is wrong. The above code prints the numbers 4, 14, and 4.
To mutate a variable, one needs to use an assignment like
score = 14 or score += 10.
Note that in Java, assignments are expressions. Thus, the following code is possible:
int score = 4;
System.out.println(score);
System.out.println(score += 10);
System.out.println(score);This would print the numbers 4, 14, and 14.
Language
Concepts
Expressible In
Other Languages
Literature References
The following papers directly or indirectly provide qualitative or quantitative evidence related to this misconception.