I will explain:
If an array is really really big and you use the
in solution, which is not bad as such, you can not break a display line after a given number of writes for a single line.
It happens to be that you can use
mod to determine if you want to add a linebreak with writeln.
Except for the modulo for 1 being 0, so I look ahead (succ()).
Even if the array is really large, we can display it neatly in blocks of the number of array elements you want per line.
I hope that helps.
Will adapt my example in a minute or so.[EDIT]
{$ifdef fpc}{$mode objfpc}{$endif}
procedure arrayprint(const values:array of integer;BreakAt:Integer; width:integer);
var
i : integer;
begin
for i := 0 to High(values) do
begin
write(values[i]:width,' ');
if (succ(i) mod BreakAt = 0) and
( i > 1) and
(i < high(values)) then
writeln;
end;
end;
var
group: array of integer;
i:integer;
begin
setlength(group,100); //0 to 99
// initialize the array
for i:= 0 to high(group) do
group[i] := i * 10;
// print the array with 10 elements per line
arrayprint(group,10, 4);
readln;
end.
Outputs:
0 10 20 30 40 50 60 70 80 90
100 110 120 130 140 150 160 170 180 190
200 210 220 230 240 250 260 270 280 290
300 310 320 330 340 350 360 370 380 390
400 410 420 430 440 450 460 470 480 490
500 510 520 530 540 550 560 570 580 590
600 610 620 630 640 650 660 670 680 690
700 710 720 730 740 750 760 770 780 790
800 810 820 830 840 850 860 870 880 890
900 910 920 930 940 950 960 970 980 990
Which means I wanted 10 elements per line, with formatted width of 4.
Now, that looks better as a single line with 100 elements, agreed?
The
mod instruction compared to 0 simply tells you there is a integer division without remainder.
So time to break....
Plz let me know if you understand it now.
This function also works for static arrays, because I use a const array of integer as parameter. (that is different from a dynamic array)
I made a slight edit to achieve that.