Logo

Programming-Idioms

History of Idiom 7 > diff from v120 to v121

Edit summary for version 121 by programming-idioms.org:
[Pascal] Fix imports: uses

Version 120

2021-10-05, 18:28:28

Version 121

2021-12-07, 09:52:19

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Imports
Classes, SysUtils
Imports
uses Classes, SysUtils;
Code
var I:Integer;
    Items: array of TObject;
[...]
  for I := 0 to high(Items) do
    if assigned(Items[I]) then
      WriteLn(Format('Item %d = %s', [I, Items[I].ToString]));
Code
var I:Integer;
    Items: array of TObject;
[...]
  for I := 0 to high(Items) do
    if assigned(Items[I]) then
      WriteLn(Format('Item %d = %s', [I, Items[I].ToString]));
Comments bubble
If you have an TObjects descendent, you can use the ToString method to get it as a String.
Comments bubble
If you have an TObjects descendent, you can use the ToString method to get it as a String.