Associative array/Iteration: Difference between revisions

m
→‎{{header|Sidef}}: simplified code
m (→‎{{header|Wren}}: Changed to Wren S/H)
m (→‎{{header|Sidef}}: simplified code)
Line 4,139:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var hash = Hash.new(
key1 => 'value1',
key2 => 'value2',
Line 4,146:
# Iterate over key-value pairs
hash.each { |key, value|
say "#{key}: #{value}";
}
 
# Iterate only over keys
hash.keys.each { |key|
say key;
}
 
# Iterate only over values
hash.values.each { |value|
say value;
}</syntaxhighlight>
{{out}}
2,747

edits