Home Segments Index Top Previous Next

175: Mainline

To change the value of a variable, you use the assignment operator, :=. Three assignment-operator containing statements appear in the following method definition:

Integer method definition • instance 
fatToCalories 
  | multiplier multiplicand result | 
  multiplier := self. 
  multiplicand := 9. 
  result := multiplicand * multiplier. 
  ^ result 
Workspace
Transcript show: 194 fatToCalories printString 
Transcript 
1746 

Of course, this method is defined awkwardly—the only reason to split the computation into multiple statements is to demonstrate variable assignment.