Programming-Idioms

History of Idiom 163 > diff from v10 to v11

Edit summary for version 11 :
New Pascal implementation by user [Bart]

Version 10

Version 11

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Code
i := Low(L);
while (i < High(L)) do
begin
  writeln(L[i],', ', L[i+1]);
  Inc(i,2);
end;
Comments bubble
Since List has no prededined meaning in Pascal, assume L is an array.
Using High() and Low() intrinsics guarantees the code also works for arrays that are not zero-based.