Logo

Programming-Idioms

  • PHP
  • Lisp

Idiom #13 Iterate over map keys and values

Access each key k with its value x from an associative array mymap, and print them.

Traversing each key and each associated object of mymap
(loop for k being each hash-key of mymap
      for x being each hash-value of mymap                                                                            
      do (format t "~A ~A~%" k x)))
foreach ($mymap as $k=>$x)
{
    echo "Key=$k, Value=$x <br>";
}
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;

use Ada.Containers;
for C in My_Map.Iterate loop
   Put_Line ("Key = " & Key (C) & ", Value = " & Element (C));
end loop;

New implementation...