Jump to content

Associative array/Iteration: Difference between revisions

(→‎{{header|Rust}}: Made example match the creating assiociated array example)
Line 1,249:
Key 4: my fave Data: 220 120 120
Key 5: black Data: 0 0 0
 
=={{header|LiveCode}}==
<lang LiveCode>put 3 into fruit["apples"]
put 5 into fruit["pears"]
put 6 into fruit["oranges"]
put "none" into fruit["bananas"]
 
put "Keys:" & cr & the keys of fruit & cr into tTmp
put "Values 1:" & tab after tTmp
repeat for each line tKey in the keys of fruit
put fruit[tkey] & comma after tTmp
end repeat
 
-- need to copy array as combine will change variable
put fruit into fruit2
combine fruit2 using comma
put cr & "Values2:" & tab after tTmp
repeat for each item f2val in fruit2
put f2val & comma after tTmp
end repeat
 
combine fruit using return and ":"
put cr & "Key:Values" & cr & fruit after tTmp
-- alternatively, use same loop as for values 1 with tkey && fruit[tKey]
 
put tTmp</lang>
Output
<lang LiveCode>Keys:
apples
pears
oranges
bananas
Values 1: 3,5,6,none,
Values2: 3,none,6,5,
Key:Values
apples:3
bananas:none
oranges:6
pears:5</lang>
 
=={{header|Lua}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.