Logo

Programming-Idioms

History of Idiom 7 > diff from v40 to v41

Edit summary for version 41 by :
[Pascal] Comment emphasize

Version 40

2016-02-05, 10:51:50

Version 41

2016-02-05, 10:53:00

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

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 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]));
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.