Logo

Programming-Idioms

History of Idiom 163 > diff from v10 to v11

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

Version 10

2018-09-06, 19:55:17

Version 11

2019-01-02, 10:57:54

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.