Associative array/Iteration: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 78:
world 2
</pre>
 
=={{header|Aime}}==
<lang aime>record r;
text s;
 
r_put(r, "A", 33); # an integer value
r_put(r, "C", 2.5); # a real value
r_put(r, "B", "associative"); # a string value
 
if (r_first(r, s)) {
do {
o_form("key ~, value ~ (~)\n", s, r[s], r_type(r, s));
} while (rsk_greater(r, s, s));
}</lang>
{{out}}
<pre>key A, value 33 (integer)
key B, value associative (text)
key C, value 2.5 (real)</pre>
 
=={{header|ALGOL 68}}==
Line 245 ⟶ 263:
(z2)[z2 value]
</pre>
 
=={{header|Aime}}==
<lang aime>record r;
text s;
 
r_put(r, "A", 33); # an integer value
r_put(r, "C", 2.5); # a real value
r_put(r, "B", "associative"); # a string value
 
if (r_first(r, s)) {
do {
o_form("key ~, value ~ (~)\n", s, r[s], r_type(r, s));
} while (rsk_greater(r, s, s));
}</lang>
{{out}}
<pre>key A, value 33 (integer)
key B, value associative (text)
key C, value 2.5 (real)</pre>
 
=={{header|App Inventor}}==
Line 496:
=={{header|C}}==
''Solution is at [[Associative arrays/Creation/C]]''.
 
=={{header|C sharp}}==
<lang csharp>using System;
using System.Collections.Generic;
 
namespace AssocArrays
{
class Program
{
static void Main(string[] args)
{
 
Dictionary<string,int> assocArray = new Dictionary<string,int>();
 
assocArray["Hello"] = 1;
assocArray.Add("World", 2);
assocArray["!"] = 3;
 
foreach (KeyValuePair<string, int> kvp in assocArray)
{
Console.WriteLine(kvp.Key + " : " + kvp.Value);
}
 
foreach (string key in assocArray.Keys)
{
Console.WriteLine(key);
}
 
foreach (int val in assocArray.Values)
{
Console.WriteLine(val.ToString());
}
}
}
}
</lang>
 
=={{header|C++}}==
Line 535 ⟶ 571:
std::cout << "key = " << key << ", value = " << value << std::endl;
}</lang>
 
=={{header|C sharp}}==
<lang csharp>using System;
using System.Collections.Generic;
 
namespace AssocArrays
{
class Program
{
static void Main(string[] args)
{
 
Dictionary<string,int> assocArray = new Dictionary<string,int>();
 
assocArray["Hello"] = 1;
assocArray.Add("World", 2);
assocArray["!"] = 3;
 
foreach (KeyValuePair<string, int> kvp in assocArray)
{
Console.WriteLine(kvp.Key + " : " + kvp.Value);
}
 
foreach (string key in assocArray.Keys)
{
Console.WriteLine(key);
}
 
foreach (int val in assocArray.Values)
{
Console.WriteLine(val.ToString());
}
}
}
}
</lang>
 
=={{header|Ceylon}}==
Line 1,456:
24
everywhere</pre>
 
 
=={{header|Harbour}}==
Line 2,528 ⟶ 2,527:
print "value = $val\n";
}</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2015.12}}
 
<lang perl6>my %pairs = hello => 13, world => 31, '!' => 71;
for %pairs.kv -> $k, $v {
say "(k,v) = ($k, $v)";
}
 
# Stable order
for %pairs.sort(*.value)>>.kv -> ($k, $v) {
say "(k,v) = ($k, $v)";
}
 
{ say "$^a => $^b" } for %pairs.kv;
 
say "key = $_" for %pairs.keys;
 
say "value = $_" for %pairs.values;</lang>
 
=={{header|Phix}}==
Line 2,817 ⟶ 2,796:
(format "~a -> ~a" k v))
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2015.12}}
 
<lang perl6>my %pairs = hello => 13, world => 31, '!' => 71;
for %pairs.kv -> $k, $v {
say "(k,v) = ($k, $v)";
}
 
# Stable order
for %pairs.sort(*.value)>>.kv -> ($k, $v) {
say "(k,v) = ($k, $v)";
}
 
{ say "$^a => $^b" } for %pairs.kv;
 
say "key = $_" for %pairs.keys;
 
say "value = $_" for %pairs.values;</lang>
 
=={{header|REXX}}==
Line 3,033:
Unique values: Netherlands, USA
</pre>
 
 
=={{header|Scheme}}==
10,327

edits