4.2 An assignment statement

counter = counter + 1  
    

This line is inside the definition of the subroutine Command0_Click. It is an assignment statement because of the use of the equal (=) symbol. At first glance, this statement makes no sense in mathematics. A variable can never equal to itself plus 1.

However, an assignment statement is not a statement saying that the right hand side (RHS) equals to the left hand side (LHS).

In an assignment, the RHS is evaluated first to a value. This value is, then, used to overwrite the value of the LHS. As a result, in this assignment statement, the current value of counter is used in the addition. The result of the addition is, then, used to update counter. As a result, each time this statement executes, it increments the value of counter by one.