RosettaCodeData/Task/Associative-array-Iteration/Sidef/associative-array-iteration.sidef

20 lines
283 B
Text
Raw Permalink Normal View History

2023-12-16 21:33:55 -08:00
var hash = Hash(
2023-07-01 11:58:00 -04:00
key1 => 'value1',
key2 => 'value2',
)
# Iterate over key-value pairs
hash.each { |key, value|
2023-12-16 21:33:55 -08:00
say "#{key}: #{value}"
2023-07-01 11:58:00 -04:00
}
# Iterate only over keys
hash.keys.each { |key|
2023-12-16 21:33:55 -08:00
say key
2023-07-01 11:58:00 -04:00
}
# Iterate only over values
hash.values.each { |value|
2023-12-16 21:33:55 -08:00
say value
2023-07-01 11:58:00 -04:00
}