RosettaCodeData/Task/Associative-array-Iteration/Nim/associative-array-iteration.nim

24 lines
409 B
Nim
Raw Permalink Normal View History

2016-12-05 23:44:36 +01:00
import tables
2017-09-23 10:01:46 +02:00
var t: Table[int,string] = initTable[int,string]()
2016-12-05 23:44:36 +01:00
t[1] = "one"
t[2] = "two"
t[3] = "three"
t.add(4,"four")
echo "t has " & $t.len & " elements"
echo "has t key 4? " & $t.hasKey(4)
echo "has t key 5? " & $t.hasKey(5)
#iterate keys
echo "key iteration:"
for k in t.keys:
echo "at[" & $k & "]=" & t[k]
#itetate pairs
echo "pair iteration:"
for k,v in t.pairs:
echo "at[" & $k & "]=" & v