Overview

Dictionary Iteration

Explores the methods for traversing associative arrays. It demonstrates using the '.Keys' property to access dictionary identifiers and performing key-based lookups during iteration to retrieve associated values.

Source Code

var colors: array [String] of String;
colors['Red'] := '#FF0000';
colors['Green'] := '#00FF00';
colors['Blue'] := '#0000FF';

// Iterating over keys
PrintLn('Keys:');
for var k in colors.Keys do
  PrintLn('  ' + k);

// Iterating over both
PrintLn('Entries:');
for var k in colors.Keys do
  PrintLn('  ' + k + ' => ' + colors[k]);

Result

Keys:
  Blue
  Green
  Red
Entries:
  Blue => #0000FF
  Green => #00FF00
  Red => #FF0000
On this page