Logo

Programming-Idioms

History of Idiom 7 > diff from v54 to v55

Edit summary for version 55 by programming-idioms.org:
[Pascal] Variable names

Version 54

2016-10-23, 21:16:36

Version 55

2016-11-27, 22:19:25

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

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Imports
Classes, SysUtils
Imports
Classes, SysUtils
Code
var Iter:Integer;
    Items: array of TObject;
[...]
  for Iter := 0 to high(Items) do
    if assigned(Items[Iter]) then
      WriteLn(Format('Item %d = %s', [Iter, Items[Iter].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.