Skip to content

Modern Map MapIterator

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Map › Map › MapIterator

MapIterator

Holds a position in a Map; each step gives a pair read through .key and .value.

Syntax

MapIterator( of TK, TV )

Notes

  • The iterator protocol -- IsValid, Value, MoveNext -- which is what for each is rewritten into. Ordinary code names the type only when the loop has to stop early, resume, or interleave with another.
  • Iteration yields a KeyValuePair, read through .key and .value.
  • Iteration order is unspecified, like the map's own.

Examples

#import "std/containers"
using containers

dim ages as Map( of ustring, integer )
ages.Put( "ada", 36 )

'' The named-halves form
for each kv in ages
    print kv.key & " " & kv.value             '' ada 36
next

'' The destructuring form, through Pairs( )
for each (who, age) in ages.Pairs( )
    print who & " is " & age                  '' ada is 36
next

Library: Map
Category: Map
Documented under: Members

Clone this wiki locally