The loop macro supports iteration over the keys, the values, or the keys and values of a hash table. The following examples show possibilities, but the full loop syntax allows more combinations and variants.
(let ((ht (make-hash-table)))
(setf (gethash 'a ht) 1
(gethash 'b ht) 2)
(loop for k being each hash-key of ht
using (hash-value v)
collect (cons k v)))
;;=> ((A . 1) (B . 2))
(let ((ht (make-hash-table)))
(setf (gethash 'a ht) 1
(gethash 'b ht) 2)
(loop for v being each hash-value of ht
using (hash-key k)
collect (cons k v)))
;;=> ((A . 1) (B . 2))
(let ((ht (make-hash-table)))
(setf (gethash 'a ht) 1
(gethash 'b ht) 2)
(loop for k being each hash-key of ht
collect k))
;;=> (A B)
(let ((ht (make-hash-table)))
(setf (gethash 'a ht) 1
(gethash 'b ht) 2)
(loop for v being each hash-value of ht
collect v))
;;=> (1 2)