Associative array/Iteration: Difference between revisions

Add SenseTalk implementation
(Add SenseTalk implementation)
Line 3,413:
value = 1
value = 2
</pre>
 
=={{header|SenseTalk}}==
<lang sensetalk>put {name:"Fluffy", type:"Rabbit", color:"White"} into animal
put "Carries a watch" into animal's habits
 
put "The animal: " & animal
put "The keys: " & keys of animal
put "The values: " & animal's values
// Keys and Values
put ,"All Properties:"
repeat with each [key,value] in animal
put !"Key: [[key]] Value: [[value]]"
end repeat
 
// Keys only
put ,"Keys:"
repeat with each [key] in animal
put key
end repeat
 
// Values only
put ,"Values:"
repeat with each [,value] in animal
put value
end repeat
 
// Using an iterator
put ,"Treating the property list as an iterator:"
put animal's nextValue -- calling any of the "next" functions begins iteration
put animal's nextKeyValue
put animal's nextKey
put animal's nextKeyValue
put animal's nextValue -- walking off the end returns a unique endValue
</lang>
{{out}}
<pre>
The animal: {color:"White", habits:"Carries a watch", name:"Fluffy", type:"Rabbit"}
The keys: ["color","habits","name","type"]
The values: ["White","Carries a watch","Fluffy","Rabbit"]
 
All Properties:
Key: color Value: White
Key: habits Value: Carries a watch
Key: name Value: Fluffy
Key: type Value: Rabbit
 
Keys:
color
habits
name
type
 
Values:
White
Carries a watch
Fluffy
Rabbit
 
Treating the property list as an iterator:
White
["habits","Carries a watch"]
name
["type","Rabbit"]
    ⓔ ⓝ ⓓ    
</pre>