RosettaCodeData/Task/Associative-array-Iteration/SenseTalk/associative-array-iteration...

32 lines
801 B
Plaintext

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