Home Segments Index Top Previous Next

379: Mainline

The following defines an array of four elements, assigns that array to a global variable, stores data in the array, and retrieves the stored data:

Workspace
Smalltalk at: #Calories put: (Array new: 4). 
Workspace
Calories at: 1 put: 570;  
         at: 2 put: 720;  
         at: 3 put: 640;  
         at: 4 put: 720. 
Transcript 
  show: 'The total calorie count is '; 
  show: ((Calories at: 1) 
         + (Calories at: 2)  
         + (Calories at: 3) 
         + (Calories at: 4)) 
        printString 
Transcript 
The total calorie count is 2650